Please Help: VBA Code to Append File

W

WayneK

Hi. I am new to using VBA with Word.

Is there a way to append all the contents of Word File "B" to the
end of Word File "A" and then save the newly appended file as
Word File "C"?

And can this be done without the files involved actually being
visibly open?

For instance, if a Word doc is open, I'd like the VBA code to take
the file C:\Donations\July.doc (not active, open) and append it to
the end of file C:\Donations\June.doc, which is also not open.
(By the way both files have several lines of text, a few tables, and
pictures -- I don't know if this matters).

Then, after the file contents are appended, a new file is created
called C:\Donations\YTD.doc.

If this cannot be done without opening the two files, can the file
"activity" (the appending and the creating of a new file) be done
behind the scenes, so to speak ... invisibly?

I appreciate your help. Thank you and have great day.

Wayne
 
J

Jezebel

You have to open the files, but yes, you can do it without the user seeing
anything --

With Documents.Open(FileName:="C:\Donations\July.doc", Visible:=False)
.Content.Copy
.Close
End With

With Documents.Open(FileName:="C:\Donations\June.doc", Visible:=False)
.Range(.Range.End - 1, .Range.End - 1).Paste
.SaveAs FileName:="C:\Donations\YTD.doc"
.Close
End With


If you're going to be doing this monthly, you'll might want to set it up as
a function that takes the file names as arguments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top