Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > Appending one document to the end of another


Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2003, 02:21 PM
radarbob radarbob is offline
Newcomer
 
Join Date: Aug 2003
Posts: 5
Question Appending one document to the end of another


My first post!


The Problem Domain
I'm writing a VBA program that builds a Word document from data pulled from a large excel spreadsheet. I build up a temporary word document, lets call it "doc1", and then when that's done I want to append it to the end of "doc2". Once appended, I throw away doc1 and build a new one w/ subsequent rows/records from the spreadsheet. Append it to doc2, repeat till I run out of data.

What I need from Y'all
I need to know how to go to the end of doc2. Then, I need to know how to properly copy all of doc1 and then append it to doc2. I need to carry over all the formatting which includes some horizontal lines (paragraph border, really), borders around a couple of paragraphs, boldface.



Some code
Here's how I'm going to the end of the doucment:
Code:
theReport.bookmarks("\EndOfDoc").select
Do I need to collapse the selection? Or do anything else prior to inserting more text?

Here is how I'm copying over the other document:
Code:
theReport.range.text = newPage.Content
The problem here is that the entire receiving document, theReport, is being overwritten from the newPage.Content. The other problem is that the formatting is disappearing in the transfer. No boldface, no borders around certain paragraphs, no horizontal line. Oh, and the user-defined bookmarks are gone too - but that's a good thing. I do know how to delete them if I had to.

Clearly I'm not fully understanding ranges and selections.

Things I'm doing right
I'm connecting to the excel spreadsheet and fetching the data. The overall program control structure is working. I'm able to get the data onto the temporary document where I want it via user-defined bookmarks. It looks like I'm putting the cursor at the end of theReport and inserting a page break.
Reply With Quote
  #2  
Old 08-14-2003, 08:17 AM
CarlR CarlR is offline
Junior Contributor
 
Join Date: Aug 2003
Posts: 331
Default

radarbob,

It's simpler than it seems.

Code:
Selection.EndKey Unit:=wdStory   ' To go to the end of the document
Selection.InsertFile FileName:="c:\Temp\MySecondFile.doc" ' To insert 2nd file
The nice thing about using the FileInsert command is that the cursor is automatically positioned at the bottom when the 2nd file is inserted -- almost in expectation that there might be MANY files to be inserted.

For more info recommend http://www.vba-programmer.com

CarlR
Reply With Quote
  #3  
Old 08-14-2003, 10:16 AM
radarbob radarbob is offline
Newcomer
 
Join Date: Aug 2003
Posts: 5
Default

Thanks for the reply CR;

I assume the code you show is inside a "with documentName " statement.

The document I'm appending is never a file, strictly speaking. I build it in memory from a blank template document, then append it, then throw it away. I do not save these interim documents.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you get document focus in Word 2000? tolan Word, PowerPoint, Outlook, and Other Office Products 4 03-26-2008 10:38 AM
Protect a Word 2000 document automatically PNeely Word, PowerPoint, Outlook, and Other Office Products 2 08-13-2003 04:23 AM
Inserting into Word document is VERY slow pjshaw Word, PowerPoint, Outlook, and Other Office Products 2 09-23-2002 04:20 AM
edit excel object in word document from VB hatchetman Word, PowerPoint, Outlook, and Other Office Products 2 07-18-2002 02:25 PM
Closing Hidden Word Document through Automation blabore Word, PowerPoint, Outlook, and Other Office Products 14 04-16-2002 11:16 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->