Copying and Pasting Between Word Docs from MS Access

CPGDeveloper

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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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,214,641
Messages
6,120,685
Members
448,977
Latest member
dbonilla0331

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