opening a word document from a visio macro

M

Mike Movchan

Ok, I am very new at this... this is what I am trying to do: I am using the
DblClickEvent [=RUNADDON("A")] to launch a macro that will open a specific
word document for the shape clicked. The first part is working however I am
having prolems getting visio to open a word doc... below is the code

Sub A()
Dim WrdDoc As Word.Document
Set WrdDoc = Documents.Open("C:\test\MyDoc.doc")
End Sub

and I get a runtime error:
Run-time error '-2032466868(86db044c)':
Visio cannot open the file because it's not a Visio file or it has become
corrupted.

Any suggestions?
 
C

Chris [Visio MVP]

Visio thinks you're making a call to Visio with your Documents.Open call.

You need something more like this:

dim wApp as Word.Application
set wApp = CreateObject("Word.Application") '... not sure if that's the
correct string...
set wDoc = wApp.Documents.Open(...)


When you Dim your variables, prefix them all with Visio.___ and Word.___ to
avoid confusion. Both apps have Document, Application, and probably some
other like-named objects. The prefixing makes things clearer to VBA.
 
A

Al Edlund

you could also do it with a hyperlink (has the added advantage that if you
have bookmarks in your word doc it can go to the bookmark)
al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top