• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 577
  • Last Modified:

Copy and Paste Text from Word doc to Word doc using VBA script

Hello

I have been trying to copy text from one word document to another word document using VBA. What actually happens is that the text from my source document does not paste to my destination document, but it pastes to itself. I have enclosed the code that I have been testing but cannot understand why it does not paste to my destination document. Any help would be appreciated. Thanks.
copyandpaste:
    Documents.Open "C:\test\doc3.docx"
    Selection.WholeStory
    Selection.Copy
    Documents("Backup Belgium (ASH)").Activate
    Windows("doc3").Activate
    Selection.EndKey wdStory
    Selection.PasteAndFormat (wdPasteDefault)
End Sub
0
ouch_mybrain_
Asked:
ouch_mybrain_
  • 2
  • 2
1 Solution
 
x-menIT super heroCommented:
Documents("Backup Belgium (ASH)").Activate
    Windows("doc3").Activate

you activate back to doc3 immediatly
0
 
x-menIT super heroCommented:
copy from doc1 to doc2:

Documents.Open "C:\test\doc2.docx"
Documents.Open "C:\test\doc1.docx"
Selection.WholeStory
Selection.Copy
Windows("doc2").Activate
Selection.PasteAndFormat (wdPasteDefault)
0
 
ouch_mybrain_Author Commented:
Thanks for the response. I have tested your code and it all works fine, but when I try to run it with my specific code I get the error of "The requested member of the collection does not exist". The difference is that my destination file has a header and a footer and I think that it is this which is causing the error. Can I paste into a specific X-Y location in the destination file. Thanks again.
0
 
ouch_mybrain_Author Commented:
Just found the solution and that is on my destination file I had the compatibility mode ticked (working in Word 2k7) and when I removed that it worked fine. Thanks again for your help.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now