Results 1 to 3 of 3

Thread: Copying and Pasting Between Word Docs from MS Access
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Oct 2008
    Location
    New York, NY
    Posts
    104
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Copying and Pasting Between Word Docs from MS Access

    I'm having a hell of time with this -- I'm sure it's something simlple I'm missing -- but from an Access application, I'm trying to combine up to 4 word docs into one word doc, and then convert it into a pdf.

    I thought I would simply copy and paste each word doc one by one into a new doc, and then save the new doc as a pdf.

    I create the word application and open a new document:

    Set objWord = CreateObject("Word.Application")
    Set docbase = objWord.Documents.Add
    docbase.SaveAs2 mypath & ".doc", 0

    I then open the word doc I want to copy from, and try and copy and paste into my new document:

    Set doc = objWord.Documents.Open(docflnm) 'docflnm is the document i want to copy from
    doc.Activate
    objWord.ActiveDocument.Range.WholeStory
    objWord.ActiveDocument.Range.Select
    objWord.ActiveDocument.Range.Copy
    docbase.Activate
    objWord.ActiveDocument.Characters.Last.Select
    objWord.Selection.Collapse
    objWord.ActiveDocument.Range.Paste
    doc.Close


    It copies and pastes, but it writes over whatever was there before -- so if I run this sequence through a loop of say 4 word documents, only the last one shows up in my new document.

    Any ideas?

  2. #2
    Board Regular
    Join Date
    May 2013
    Posts
    654
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Copying and Pasting Between Word Docs from MS Access

    Office 2007
    Access novice. Sometimes trying to give something back

  3. #3
    Board Regular
    Join Date
    Oct 2008
    Location
    New York, NY
    Posts
    104
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Copying and Pasting Between Word Docs from MS Access

    Thank You!!

    I don't know why I made it so complicated -- for anyone looking to do this, this is the code that worked for me:

    Set objWord = CreateObject("Word.Application")
    Set docbase = objWord.Documents.Add
    docbase.SaveAs2 mypath & ".doc", 0

    'I run a loop defining the word files I want to insert into the word file I just created, calling it docflnm,

    docbase.Activate
    objWord.Selection.InsertFile (docflnm)

    That's It! -- Easy Peezy




    Quote Originally Posted by welshgasman View Post

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •