View Single Post
  #8   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default How do I merge several documents in one package and retain set

Check that in the Modify Styles dialog that the Automatically Update Styles
box is not checked.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"SlavetoWasabi" wrote in message
...
Doug -

One follow-up question. I'm noticing that in some instances the font in
the
original document is not retained when the text is moved to the target
document. It appears that I can address this by using the Paste Options
button and selecting Retain original formatting. Is there a way I can
access this functionality programatically?

Thanks,
Chris

"Doug Robbins - Word MVP" wrote:

Hi Chris,

Do it this way:

Dim Target As Document, Source As Document
Dim trange As Range, srange As Range
'Start an Instance of Word, or grab an already-existing one
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err Then
Err.Clear
Set WordApp = GetObject("", "Word.Application")
End If

'Supress merge warning message about data, otherwise document not opened
as
merge mail document
WordApp.DisplayAlerts = wdAlertsAll

'Hide Word until merging is complete,
WordApp.Visible = False
WordApp.WindowState = wdWindowStateMinimize

'Open master (blank) document
Set Target = WordApp.Documents.Open(FileName:=MainDocument,
ReadOnly:=True)

'Determine the name used by Word for the Main Document
'so that it can be closed after the Merge is completed
MainDocument = StrRev(MainDocument)
n = InStr(MainDocument, "\")
MainDocument = StrRev(MainDocument)
If n 0 Then
MainDocument = Right(MainDocument, n - 1)
End If

n = InStr(MainDocument, ".")
If n 0 Then
MainDocument = Left(MainDocument, n - 1)
End If

'Insert documents to be included in package into master document
With Target
For n = 0 To lstDocuments.ListCount - 1
If lstDocuments.Selected(n) = True Then
Set Source = Documents.Open(lstDocuments.List(n))
If Err Then
MsgBox "Unable to locate document: " &
lstDocuments.List(n),
vbInformation
Err.Clear
End If
With Source
Set srange = .Range
srange.Collapse wdCollapseEnd
srange.InsertBreak wdSectionBreakNextPage
End With
Set trange = .Range
trange.Collapse wdCollapseEnd
trange.FormattedText = Source.Range.FormattedText
Source.Close wdDoNotSaveChanges
End If
Next
'Change the next page section break at the end of the last document
inserted to a continuous section break
Set trange = .Range
trange.Collapse wdCollapseEnd
trange.Sections(1).PageSetup.SectionStart = wdSectionContinuous
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"SlavetoWasabi" wrote in
message
...
Doug -

Here's a code snippet. Some of this isn't relevant to the issue, but
you
should have what you need in here.

Thanks again for your help,
Chris
************* Start of code snippet *************

'Start an Instance of Word, or grab an already-existing one
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err Then
Err.Clear
Set WordApp = GetObject("", "Word.Application")
End If

'Supress merge warning message about data, otherwise document not
opened
as
merge mail document
WordApp.DisplayAlerts = wdAlertsAll

'Hide Word until merging is complete,
WordApp.Visible = False
WordApp.WindowState = wdWindowStateMinimize

'Open master (blank) document
WordApp.Documents.Open FileName:=MainDocument, ReadOnly:=True

'Determine the name used by Word for the Main Document
'so that it can be closed after the Merge is completed
MainDocument = StrRev(MainDocument)
n = InStr(MainDocument, "\")
MainDocument = StrRev(MainDocument)
If n 0 Then
MainDocument = Right(MainDocument, n - 1)
End If

n = InStr(MainDocument, ".")
If n 0 Then
MainDocument = Left(MainDocument, n - 1)
End If

'Insert documents to be included in package into master document
For n = 0 To lstDocuments.ListCount - 1
If lstDocuments.Selected(n) = True Then
WordApp.Selection.InsertFile FileName:=lstDocuments.List(n),
ConfirmConversions:=True
If Err Then
MsgBox "Unable to locate document: " & lstDocuments.List(n),
vbInformation
Err.Clear
End If
If n lstDocuments.SelCount - 1 Then
'Now including section break at the end of each document per message
board
post
'in attempt to retain individual document formatting
' WordApp.Selection.InsertBreak wdSectionBreakNextPage
End If
End If
Next

'Indicate that the merge is to a new document (rather than the printer)
WordApp.ActiveDocument.MailMerge.Destination = wdSendToNewDocument
If Err Then
MsgBox Err.Description
Err.Clear
Exit Sub
End If


'Perform the mail-merge
WordApp.ActiveDocument.MailMerge.Execute
If Err Then
MsgBox Err.Description
Err.Clear
Exit Sub
End If

'Close the master document
g.LocateWordWindow WordApp, MainDocument
WordApp.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges


'Set focus to the window containing the merged document
g.LocateWordWindow WordApp, "Form Letters"


'View
If chkView.Value = 0 Then
WordApp.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Else
WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
End If


'Release the WordApp Object, and Exit
WordApp.Exit
Set WordApp = Nothing

******** End of Code Snippet **********

"Doug Robbins - Word MVP" wrote:

Best if you show us the complete code that you are using.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"SlavetoWasabi" wrote in
message
...
Doug -

I'm using the InsertFile command to insert the documents:

WordApp.Selection.InsertFile FileName:=lstDocuments.List(n),
ConfirmConversions:=True

Settings that seem to revert back to the main "blank" document
settings
include margins and the spacing between the header and footer and
the
edge
of
the paper.

Thanks,
Chris

"Doug Robbins - Word MVP" wrote:

Are the settings of the individual documents retained in the mail
merge
main
document? How are you inserting the documents into the blank
"main"
document - copy and paste or using an IncludeText field?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"SlavetoWasabi" wrote in
message
...
I'm trying to do a mail merge where I assemble a package from
several
different documents, which can vary depending on the scenario,
then
perform a
mail merge. Each of these documents may have different margins,
headers,
header margins, etc. I currently have a blank "main" document
that
I
insert
each file into, then perform the mail merge. Each document,
before
being
included in the main document, has a "Section Break - Next Page"
at
the
bottom. However, the settings reflected in each individual
document
are
not
being retained in the merged product. Is there a way to do what
I'm
trying
to do?