Copying and Pasting Between Word Docs from MS Access

CPGDeveloper

Board Regular
Joined
Oct 8, 2008
Messages
189
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?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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




 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top