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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sporadic error with Visio embedded in Word

Status
Not open for further replies.

groston

IS-IT--Management
Dec 31, 2001
141
US
I have written an Word macro that generates a Visio chart (based on information automtically gathered from a Word document combined with user input) and pastes this chart into the document. The structure of the program looks like this:

+++ begin psuedo code +++

Sub BuildForm
Load UserForm
' gather info form word document
' add stuff to form
UserForm.Show
Set UserForm = Nothing
End Sub

Sub ClickButton ' on UserForm
' Build data structure, DS
DrawObject DS ' call subroutine to generate object

Selection.Paste <<<=== error occurs here
Me.Hide
End Sub

Sub DrawObject (DS)
Set appVisio = CreateObject(&quot;visio.application&quot;)
' at stuff to page based on DS

appVisio.ActiveWindow.SelectAll
appVisio.ActiveWindow.Selection.Copy

docObj.Saved = True
appVisio.Quit
End Sub

+++ end pseudo code +++

This works - most of the time.

On occasion, when I run this code, I get the following error (at the line indicated above):

Run time error '4605':
This method or property is not valid because the Clipboard is empty or not valid.

If I click 'cancel' and run the code again, it works fine.

Can you please suggest why this error is occurring and what can be done to prevent it.

Thank you.


----

Gerry Roston
gerry@pairofdocs.net
 
Is it possible that Word is losing focus while your code is running? If Word doesn't have the focus, you can Hit CTRL+C like a madman - it won't copy the Word selection, therefore the clipboard is empty.
--> prevent this by activating the respective window shortly before copying.
What does the selection contain? Perhaps it is possible not to do this via copy/paste, but via direct assignment of the respective object to be embedded. :cool:

Regards,
MakeItSo

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
Andreas,

Thanks for the response.

What makes this so puzzling is that it works more times than not...

Your comment &quot;via direct assignment of the respective object to be embedded&quot; is intriguing. Once I have built the Visio diagram, and have the cursor positioned properly within Word, what would I do to embed the Visio object in Word if not cut/paste?

Thanks.

----

Gerry Roston
gerry@pairofdocs.net
 
Hi Gerry!

Sorry it took me so long - I'm on vacation... ;-)
What I mean is the function you use from the tool bar:
Insert - Object - From File
and choose your object.
This is what the code looks like:
Code:
Selection.InlineShapes.AddOLEObject ClassType:=&quot;Visio.Drawing.6&quot;, FileName _
        := _
        &quot;full path to your *.vsd&quot; _
        , LinkToFile:=False, DisplayAsIcon:=False

Does that help?
[santa2]
Andy
 
Andy,

Thanks!

Yes, quite helpful. But...

I never save the Visio diagram as a file. I will need to look at this method to see if I can not use the FileName parameter.

p.s. Hope you enjoyed your vacation!

----

Gerry Roston
gerry@pairofdocs.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top