|
-
Apr 7th, 2005, 08:45 AM
#1
Thread Starter
New Member
Error when closing Word application after copy to clipboard
I'm running the following VBA macro in Excel.
The macro creates a Word application which opens an existing document, copies its contents to the clipboard. It then opens a new word application and pastes the clipboard contents into a new document.
So far so good. But when I quit the first application I get a Program Error which says "Winword.exe has generated errors and will be closed, etc..."
What am I doing wrong?
Sub myFunc()
currDir = Worksheets.Application.ThisWorkbook.Path
Set appWD = CreateObject("Word.Application.9")
appWD.Visible = True
Set tempDoc = appWD.Documents.Open(currDir & "\" & "V.DOC")
appWD.ActiveDocument.Content.Copy
Set appWD_NewDoc = CreateObject("Word.Application.9")
appWD_NewDoc.Visible = True
appWD_NewDoc.Documents.Add
appWD_NewDoc.ActiveDocument.Content.Paste
tempDoc.Close (wdDoNotSaveChanges)
Set tempDoc = Nothing
appWD.Quit 'THIS IS WHERE THE ERROR OCCURS!!
Set appWD = Nothing
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|