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("visio.application"
' 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
+++ 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("visio.application"
' 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