Log in

View Full Version : Paste Command Failing



ill_comms
08-19-2008, 10:31 PM
Hi, I have a Word Macro that does the following:

1. Opens Word document with macro in it "DOC1".
2. Creates a new document "DOC2".
3. Opens another document "DOC3" that is acting like a template of sorts.
4. DOC2 is selected and copies the entire document to the clipboard. Then pastes it into DOC3.



Documents(templateDocumentName).Select
Selection.WholeStory
Selection.Copy
Documents(newDocumentName).Activate
Selection.PasteAndFormat (wdPasteDefault)


This works perfectly in XP however falls over when run in Vista, both machines are using Office 2003.

The error is occuring on: "Selection.PasteAndFormat (wdPasteDefault)" and only producing a "Command Failed" error.

What could be causing this and does anyone have a fix?

Regards Hayden

ill_comms
08-20-2008, 08:10 PM
Hi thanks for your help! I have fixed it. I believe it was because I had just activated the document not actually selected it, so the cursor for instance was not in the document.



Documents(templateDocumentName).Select
Selection.WholeStory
Selection.Copy
Documents(newDocumentName).Activate
Documents(newDocumentName).Select
Selection.WholeStory
Documents(newDocumentName).PasteAndFormat (wdPasteDefault)


Funny that the previous version work with XP not vista though?

Regards Hayden