![]() |
#1
|
|||
|
|||
![]()
Hello there!
I have troubles getting appending of 2 documents to work. I have a document A that refers to a scond document B via INCLUDETEXT. Now the thing is: document B is a template that is setup to pull data from a .csv file via mail merge. Is it possible that If I open up the document A to start the mail merge on document B (because it is referenced via INCLUDETEXT)? Or do I need to use VBA for that? Background: Whenever I want to generate the complete file which consists of document A prepended to document B I want document be to be filled with the right data from the .csv. Any help apreciated! Regards svo |
#2
|
||||
|
||||
![]()
A mailmerge main document can use an INCLUDETEXT field to incorporate another document, whether absolutely or conditionally. No VBA is required for this - just field coding.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Well the problem here actually is that the main document is not a mail merge document. Instead it should be trying to append a document that in fact is a mail merge document. And upon appending it the mail merge doc should be up to the latest changes from the data source.
|
#4
|
||||
|
||||
![]()
That suggests you have the documents organised the wrong way around - your ordinary document should be incorporated into the mailmerge main document, whether by pasting the content into it directly or via an INCLUDETEXT field. In this respect it is of no consequence whether the content from your ordinary document is incorporated before or after the mailmerge fields, or even before and after them. Simply incorporating a mailmerge main document into another document doesn't turn the ordinary document into a mailmerge main document and, hence, the mailmerge won't work unless the ordinary document is turned into a mailmerge main document by connecting it to the data source.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
I understand that you say I have my documents organised the wrong way. But I guess it's the nature of the document. To be a bit more specific: the main document (the static one) is actually altered in a first step with some kind of templating engine. It holds all the customer info. The customer can have multiple ware houses. So to the general info should be a list appended with all the warehouse's info.
I think I will go the direction with macros, since I can use a document macro that is executed on opening the main document to open the warehouse mail merge document, sets up the data sourcde and startes the mail merging. I will update this post when I have a working solution.ö Thanks anyway! |
#6
|
|||
|
|||
![]()
Hello there!
Since I said I will do a follow up post here that manaes to do what I wanted all along.
I used this call a VBA document macro to get into the process. When the call is made, I can be sure the template is filled with all the values from the templating engine. Now with VBA I
Code:
Public Sub AfterTemplating() Dim SourceDocument As Document Dim warehouseListTemplate As Document ' For jumping windows I need a reference Set SourceDocument = Documents(ActiveDocument.Name) ' opening the warehouse tmplate Set warehouseTemplate = Documents.Open(FileName:="warehouseTemplate.doc") ' Set it as the ActiveWindow and ActiveDocument warehouseTemplate.Activate ' Add the DataSource which I beforehand have generated warehouseTemplate.MailMerge.OpenDataSource Name:="warehouses.xls" ' start the mail merge and get the resulting mail merged document warehouseTemplate.MailMerge.Execute ' save the mail merged document ActiveDocument.SaveAs ("warehousesMerged.doc") ' Do not alter the template and close it Documents(warehouseTemplate.doc").Close SaveChanges:=False ' close the mail merged document Documents("warehousesMerged.doc").Close ' Switch ActiveWindow and ActiveDocument to the original document Documents(SourceDocument).Select ' Goto to the Bookmark at the page before last page Selection.GoTo What:=wdGoToBookmark, Name:="warehouseregister" ' Select the bookmark and add a INCLUDEFIELD with the mail merged document Selection.Range.Select Selection.Fields.Add Range:=Selection.Range, Type:=WdFieldType.wdFieldIncludeText, Text:=Chr(34) & "warehousesMerged" & Chr(34), PreserveFormatting:=False ' Update the fields so the included file gets displayed ActiveDocument.Fields.Update ' Delete the Section breaks so that my page numbering in the footer is not screwed DeleteSectionBreaks End Sub Sub DeleSectionBreaks() Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^b" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .MatchFuzzy = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub |
![]() |
Tags |
includetext, mail merge |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
File name and Doc settings are printing and appending to my Word docs. | wranglerman4you | Word | 4 | 12-30-2013 12:45 AM |
![]() |
rcVBA | Word VBA | 4 | 05-21-2013 11:40 AM |
![]() |
BriMan83 | Mail Merge | 1 | 04-24-2013 11:35 PM |
converting a word document to a data file for mail merge | drsuis | Mail Merge | 4 | 02-21-2013 03:34 PM |
Merge Fields and Static Text | kbranden | Mail Merge | 1 | 06-15-2011 09:02 AM |