Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Please Help: VBA Code to Append File

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WayneK - 18 Aug 2006 05:37 GMT
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
Jezebel - 18 Aug 2006 06:05 GMT
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.

> Hi. I am new to using VBA with Word.
>
[quoted text clipped - 21 lines]
>
> Wayne
WayneK - 18 Aug 2006 12:13 GMT
Thank you, Jezebel, for your help, which was great. The code
works super.

Wayne

> Hi. I am new to using VBA with Word.
>
[quoted text clipped - 21 lines]
>
> Wayne
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.