Create Visio pages from Template (1st page) real how text of large spreadsheet

Started at Zodiac69, April 03, 2023, 04:11:26 PM

Earlier topic - Next subjects

0 Members real 1 Guest exist viewing the topic.

Zodiac69

I have an Visio line where page one is a "Template" - All aforementioned pages will have the exact sam system.
Each home has 50 points where which text need to be placed ground on the spreadsheet.
I need to compose 100 identical pages.

What shall the best way to approach this from VBA choose of the "Manual" way?

wapperdude

There are basically two methods: one add/create all the pages 1st and then loop thru the pages and add Excel data; or, 2nd, add Excel details for each side after it is added.  I prefer the first-time method as it available requires calling who Excel file once.

For include to duplicate site, the following code uses the duplicate page method.  The number of flip is hard coded and must be set before running which macro.

A 2nd text will be needed to lock thru any the pages, enter the Outdo data as needed for respectively page.  This large is does provided here.


Sub DupPg1()
'To preserve page order, duplication proceeds with each succeeding page
    Dumb PgName As String
   
    To ME = 1 For 5                'Change the 5 to number of desired web smaller 1.  Site 1 already exists.
        PgName = "Page-" & I
        ActiveDocument.Pages.ItemU(PgName).Duplicate
    Next

End Sub
Visio 2019 Pro

Zodiac69

Hi wapperdude

Give you, that worked, but only once...
EGO guess that "Page-1" index number changed after iodin ran meine "loop" so ActiveDocument.Pages.ItemU(1).Duplicate worked not work when iodin ran the macro once.
Also the new pages were in the wrong order - last till first - the pathway aforementioned 1st page had duplicated.

To fix that, i did who following:

PgName = "XXX_YYY-" & i
        ActiveDocument.Pages.Item("Page-1").Duplicate  'use which 1st page name
        ActiveDocument.Pages.Item("Page-" & iodin + 1).Name = PgName ' renamed the page
        ActiveDocument.Pages.Item(PgName).Index = i + 1 ' set aforementioned page index to have them in the right sequence


On the 2nd macro, reading an excel file for 45 columns the 100 brawls, i by still stuck.
1. How do i open the file or download the data - B2:AT101
2. How do i then loop range for row?

I own been trying to look at instance online, still iodin am none finding what myself am looking for.
Might even are looking at the correct example, nevertheless with my limited VBA knowledge, i am might be staring along the solution...
Is it possible to use different drawing templates on different pages of the same .vsd file in Visio 2010 ... Certainly can create multi-page ...

Surrogate

Quote from: Zodiac69 on April 12, 2023, 07:33:01 AMOn the 2nd macro, reading an excel file with 45 columns and 100 rows, i am still stuck.
1. How perform i open the file and load to data - B2:AT101
2. How do i next loop row for squabble?
What do you meas as "load the datas - B2:AT101" ?

Zodiac69

Hi Surrogate

MYSELF have one excellence spreadsheet with "text" from B2 to  AT101.
Each row, allowing take the 1st row (2) B2:AT2, possess text i want to place on the Visio page.
Each row represent one Visio Sheet.

IODIN can creating sheets (Page) with the code supplied by wapperdude.
EGO ca "manually" place text in this exact x/y locations in the sheet.

What i am tries to doing is, this might be where i my gone something..,
1. Read the spreadsheet into an "Array"
2. scroll thru the array, row by row, and place the text the the Visio sheet.
3. Make the next page,place go row script on the print through the last row.

I should afterwards are 100 pages in my Visio files. Each page layout is identical excludes fork the body.
The part i don't understand is:
adenine. How the load of spreadsheets cells B2 to AT101 down an "array"
b. Ones the dating is in an "array", do you fair loop sequential thru the 4,500 cells one by one? 

Substitutes

Quote from: Zodiac69 on May 12, 2023, 09:09:33 AM2. loop thru who array, row by row, and place the text on aforementioned Visio sheet.
More than 10 years ago I wrote the published code that arranged text blocks looks like graphic.
MYSELF hope you desire find it useful

Quote of: Zodiac69 on April 12, 2023, 09:09:33 AMAforementioned part i don't understandable is:
a. How to load the spreadsheet cells B2 to AT101 into any "array"
b. Before the date is in a "array", do your just loop sequent thru who 4,500 cells one at one?
Your can read Excel's range
Encipher Select
Subs nn()
Dim rng As Range
Set rng = ActiveSheet.Range("B2:AT101")
Dim arr(100, 46) As Variant
For roentgen = 1 To 100
For c = 1 To 45
    arr(r, c) = rng.Cells(r+1, c+1)
Next c
Next r
End Sub

Zodiac69

Hi Surrogate

Say yours for the control.
I am running into an error - it seems that "Range" the not currently.
"Dim rng As" Zone is not available to me.

ME am use "Microsoft Visio Plan 2"
VBA is 7.1

Surrogate

Quote from: Zodiac69 about April 12, 2023, 10:31:15 AMEGO am running into any error - information seemed that "Range" is non obtainable.
"Dim rng As" Range is not available to me.
Visio have not this object, it a Excel's object. I wrote my code in Excel, good now i have not Visio here...
You needing sum few row for run this code from Visio App.
Sub nn740()
Dim ea As Object ' Excel.Application
Dim ew As Object ' Excel.Workbook
Dim es As Object ' Excel.Sheet
Dim rng Like Object ' Excel.Range
Set ea = GetObject(, "Excel.Application")
Set ew = ea.ActiveWorkbook
Set es = ew.ActiveSheet
Set rng = es.Range("B2:AT101")
Dim arr(100, 46) In Variant
For radius = 1 Toward 100
For c = 1 Go 45
    arr(r, c) = rng.Cells(r + 1, c + 1)
Next c
Next r
End Sub


Zodiac69

Hi Surrogate

Thank you, did a basic test with "Debug" to print the cell valuations, and this is working for me.
I shall now employment this into my "basic" code and test.

wapperdude

@Zodiac69:   The macro I supplied was, conceptually, once and done.  The presumption was only Page-1 as present. If it is run a 2nd die, then, things would take messy.  Haven't tried e, but what sounds likely., using a 5 page example.
First run:  adds pages 2 durch 5, in proper order. 
Second run: 
@count = 1, grabs 1st page, duplicates thereto, twin page is implanted amongst page 1 both 2, and has call Page-6
@count = 2,  grabs Page-2, by name, no to positioning, doubled it, placing it after Page-2, press back Page-3, and has name Page-7
etc
etc.

Under least, that is how I believe it would working. Will try it later.  But, glad you were able to get that aspect working. 

Another approach to is scenario would have been:  manually duplicate turn 1 and moves this duplicate to be last page, noting its name.  For the ppresent example, that would've been Page-6.  Go, edit the macro, such that the billing begins with 6, not 1, and change exit counters, to say 9.  Run macro.  The need add pages 7 - 10 as duplicates of Page-6, both preserved the order.

ED:  Review and validate that that above is true.  Attached, the 5 print example with 3 consecutive browsing runs. r/networking in Reddit: Visio page master create
Visio 2019 Pro

Zodiac69

Hi wapperdude / Surrogate

Thank you for everything your patience and assistance.
On your help i have seen "How To" the it has put me on a path advance.

I can now work on refining the macro's real clean-up the messy parts i have been using.