A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How do I merge several documents in one package and retain setting



 
 
Thread Tools Display Modes
  #1  
Old April 30th, 2009, 09:00 PM posted to microsoft.public.word.mailmerge.fields
SlavetoWasabi
external usenet poster
 
Posts: 8
Default How do I merge several documents in one package and retain setting

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?
  #2  
Old April 30th, 2009, 10:05 PM posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default How do I merge several documents in one package and retain setting

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?


  #3  
Old May 1st, 2009, 12:05 AM posted to microsoft.public.word.mailmerge.fields
SlavetoWasabi
external usenet poster
 
Posts: 8
Default How do I merge several documents in one package and retain set

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?



  #4  
Old May 1st, 2009, 08:06 AM posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default How do I merge several documents in one package and retain set

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?




  #5  
Old May 1st, 2009, 06:34 PM posted to microsoft.public.word.mailmerge.fields
SlavetoWasabi
external usenet poster
 
Posts: 8
Default How do I merge several documents in one package and retain set

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?




  #6  
Old May 1st, 2009, 11:33 PM posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default How do I merge several documents in one package and retain set

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?





  #7  
Old June 5th, 2009, 10:13 PM posted to microsoft.public.word.mailmerge.fields
SlavetoWasabi
external usenet poster
 
Posts: 8
Default How do I merge several documents in one package and retain set

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?






  #8  
Old June 5th, 2009, 11:42 PM posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
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?







  #9  
Old June 6th, 2009, 06:01 AM posted to microsoft.public.word.mailmerge.fields
SlavetoWasabi
external usenet poster
 
Posts: 8
Default How do I merge several documents in one package and retain set

Doug -

That didn't seem to help. I had to upgrade to Office 2007 anyway, so I went
ahead and did that today. Still having the same problems, so I've been
trying out the pasting manually. I set all the default paste options under
the Advanced button to "Keep Source Formatting". However, when I do "Paste
Special", then "Formatted Text", the source formatting is not maintained and
when I click on the Paste Options icon that displays after the paste, the
paste option is always set to "Use Destination Styles". When I change it to
"Keep Source Formatting", then everything shows up the way I want it. I get
the same behavior from my automation. Interestingly enough, when I'm testing
the copy/paste out manually in Word, if I select "Paste" instead of "Paste
Special", it seems to be pasting with the "Keep Source Formatting" option,
and the document looks fine. What do I need to change in my automation to
replicate this behavior?

Thanks,
Chris

"Doug Robbins - Word MVP" wrote:

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?








  #10  
Old June 6th, 2009, 09:23 AM posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default How do I merge several documents in one package and retain set

Instead of the command

trange.FormattedText = Source.Range.FormattedText

try

Source.Range.Copy
trange.Paste

--
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 -

That didn't seem to help. I had to upgrade to Office 2007 anyway, so I
went
ahead and did that today. Still having the same problems, so I've been
trying out the pasting manually. I set all the default paste options
under
the Advanced button to "Keep Source Formatting". However, when I do
"Paste
Special", then "Formatted Text", the source formatting is not maintained
and
when I click on the Paste Options icon that displays after the paste, the
paste option is always set to "Use Destination Styles". When I change it
to
"Keep Source Formatting", then everything shows up the way I want it. I
get
the same behavior from my automation. Interestingly enough, when I'm
testing
the copy/paste out manually in Word, if I select "Paste" instead of "Paste
Special", it seems to be pasting with the "Keep Source Formatting" option,
and the document looks fine. What do I need to change in my automation to
replicate this behavior?

Thanks,
Chris

"Doug Robbins - Word MVP" wrote:

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?









 




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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:15 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.