Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
How do I merge several documents in one package and retain set
Doug -
That resulted in the same behavior, but this command seems to have worked: trange.PasteAndFormat (wdFormatOriginalFormatting) I turned on the macro recording, and that's the command that Word was using when I clicked on "Paste". Thanks again for all your help, Chris "Doug Robbins - Word MVP" wrote: 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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I retain the original date on word documents? | Microsoft Word Help | |||
Word 2007: how to retain the zoom level setting for incoming mail | Microsoft Word Help | |||
Switches in Table of Authorities - retain formatting does not retain character styles | Formatting Long Documents | |||
Word 2003 does not retain top margin setting | Page Layout | |||
How to retain a format change during a merge | Mailmerge |