Group:  Microsoft Word ยป microsoft.public.word.vba.beginners
Thread: Please Help: VBA Code to Append File

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Please Help: VBA Code to Append File
"WayneK" <WayneKind[ at ]gmail.com> 18.08.2006 04:37:06
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

Re: Please Help: VBA Code to Append File
"Jezebel" <warcrimes[ at ]whitehouse.gov> 18.08.2006 05:05:03
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.






"WayneK" <WayneKind[ at ]gmail.com> wrote in message
news:1155875826.781475.125540[ at ]b28g2000cwb.googlegroups.com...
[Quoted Text]
> 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
>


Re: Please Help: VBA Code to Append File
"WayneK" <WayneKind[ at ]gmail.com> 18.08.2006 11:13:59
Thank you, Jezebel, for your help, which was great. The code
works super.

Wayne


WayneK wrote:
[Quoted Text]
> 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

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net