|
-
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
-
Apr 7th, 2005, 10:41 AM
#2
Addicted Member
Re: Error when closing Word application after copy to clipboard
HI,
ive used your code and it worked fine. Win NT, Excel 2002, word 2002
i did have to change it slightly:
VB Code:
CreateObject("Word.Application.9")
changed to:
VB Code:
CreateObject("Word.Application")
if you fail to plan, you plan to fail
-
Apr 8th, 2005, 01:58 AM
#3
Thread Starter
New Member
Re: Error when closing Word application after copy to clipboard
Thanks for your answer !
I forgot to mention that I am using Excel 2000 and that my application was run on Win2000 Professional.
It seems to work fine on XP though.
Still a mystery why the error occurs in 2K, I've tried it on 2 different machines.
Last edited by perronnberg; Apr 8th, 2005 at 02:03 AM.
-
Apr 8th, 2005, 04:04 AM
#4
Re: Error when closing Word application after copy to clipboard
 Originally Posted by perronnberg
I'm running the following VBA macro in Excel.
Code:
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")
appWD_NewDoc.Visible = True
appWD_NewDoc.Documents.Add
'---- pastes v.doc content into the new doc
appWD_NewDoc.ActiveDocument.Content.Paste
'---- clears up the temp doc (v.doc)
tempDoc.Close (wdDoNotSaveChanges)
Set tempDoc = Nothing
'---- You haven't saved or closed the copied doc?
appWD.Quit 'THIS IS WHERE THE ERROR OCCURS!!
Set appWD = Nothing
End Sub
Perhaps the error is that you are closing the app but not having saved/closed the new doc?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Apr 8th, 2005, 06:37 AM
#5
Thread Starter
New Member
Re: Error when closing Word application after copy to clipboard
Thanx for the suggestion, but...
I tried saving and closing the new doc without getting rid of the error.
Code:
appWD_NewDoc.ActiveDocument.Save
appWD_NewDoc.ActiveDocument.Close
appWD_NewDoc.Quit
Set appWD_NewDoc = Nothing
appWD_Template.Quit
Set appWD_Template = Nothing
-
Apr 8th, 2005, 07:19 AM
#6
Re: Error when closing Word application after copy to clipboard
Just ran that code.. stepped through - no problem ... from excel opening word and a doc. Perhaps it is the content of the v.doc?
Try with only a line or two of test data?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Apr 8th, 2005, 08:35 AM
#7
Thread Starter
New Member
Re: Error when closing Word application after copy to clipboard
Thanx again !
You seemed to have hit the spot, There's something in my document that causes the error!!
I'll just have to figure out what part. Besides plain text the doc has tables and bookmarks.
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
|