Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting Visio Drawing into Word Doc through VB

Status
Not open for further replies.

kldps

Programmer
May 13, 2002
13
US
I have a Visual Basic program which uses Word automation to send database data to form fields in a Word template which is then printed. This part works fine. I now need to insert a linked Visio diagram into the word document using OLE and resize it to a certain size to fit into the template. The filename of the visio diagram is dynamic. This is the code I'm trying to use to do this- I am getting an Error 4198- Command Failed (love those descriptive error messages!) strVisioPath is a variant variable containing the path and file name of the visio file. I have tried it with the shapes and inlineshapes objects.

Code:
objWordDoc.InlineShapes.AddOLEObject Filename:=strVisioPath, linktofile:=True, DisplayAsIcon:=False, Left:=25, Top:=50, Width:=100, Height:=100

Any suggestions would be greatly appreciated! Thanks.
 
Contrary to Word VBA help, you may need to include the ClassType parameter (even though you already include the filename):

ClassType:="Visio.Drawing.6"

At least, that's what works for me, and that's what the macro recorder produces for this operation when done manually. If it still doesn't work, try temporarily removing the size parameters to make sure it's not the resizing that is failing.

Rob
[flowerface]
 
Thanks for the info! I did use the ClassType parameter but I also had to do a couple of other things. I had to set a Range object to a bookmark (named "Visio") in my document and then use the Anchor parameter and point that to the range object. I also changed it back to a Shapes object. The code that worked was:

Code:
Set myRange = objWordDoc.Bookmarks("Visio").Range

objWordDoc.Shapes.AddOLEObject ClassType:="Visio.Drawing.6", Filename:=strVisioPath, LinkToFile:=True, DisplayAsIcon:=False, Left:=100, Height:=225, Width:=350, Anchor:=myRange

Thanks again for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top