简体   繁体   中英

VB code to place specific page of Visio document into Word

I've been working on a Word macro that includes a step allowing the user to select and insert a Visio file into the active Word document. Since many of the source Visio files are multipaged, and the specific Visio drawing to place in Word could be on any page of the Visio document, I need a way to allow the user to select the page they want to place.

Currently, my VBA code uses Appplication.FileDialog(msoFileDialogFilePicker) to set a variable for the Visio drawing's filepath (myVisioPath), then creates a variable for the Visio file and inserts it it into the Word doc as follows:

Dim myViz As InlineShape
Set myViz = ActiveDocument.InlineShapes.AddOLEObject(ClassType:="Visio.Drawing.15", FileName:=myVisioPath, LinkToFile:=False, DisplayAsIcon:=False, Range:=Selection.Range)
myViz.Select `Selects the Visio for subsequent actions`

The current working version of the macro selects whatever is on page 1 of the selected Visio file. I need a way to allow the user to select page 2, or page 3, or whatever page the target drawing is on in the Visio file. Currently, I'm thinking of creating a userform to allow choosing a page number, but I'm open to suggestions.

The post by Mathieu Guindon led me to the answer (would have voted it as the answer but that doesn't appear to be an option). Anyway, the code posted at Choose active page in Visio provided the basis of my solution. Set a variable for the Visio.Application object and refer to it to get both the page count of the user-selected Visio file (for error trapping if the user selects a page number that isn't available in the file) and to copy the user-selected page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM