Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-09-2015, 02:59 AM
svo svo is offline Appending a mail merge document to a static file Windows 7 64bit Appending a mail merge document to a static file Office 2003
Novice
Appending a mail merge document to a static file
 
Join Date: Jun 2015
Posts: 7
svo is on a distinguished road
Default Appending a mail merge document to a static file

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
Reply With Quote
  #2  
Old 06-09-2015, 07:50 PM
macropod's Avatar
macropod macropod is offline Appending a mail merge document to a static file Windows 7 64bit Appending a mail merge document to a static file Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,371
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 06-09-2015, 10:56 PM
svo svo is offline Appending a mail merge document to a static file Windows 7 64bit Appending a mail merge document to a static file Office 2003
Novice
Appending a mail merge document to a static file
 
Join Date: Jun 2015
Posts: 7
svo is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 06-09-2015, 11:05 PM
macropod's Avatar
macropod macropod is offline Appending a mail merge document to a static file Windows 7 64bit Appending a mail merge document to a static file Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,371
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 06-09-2015, 11:20 PM
svo svo is offline Appending a mail merge document to a static file Windows 7 64bit Appending a mail merge document to a static file Office 2003
Novice
Appending a mail merge document to a static file
 
Join Date: Jun 2015
Posts: 7
svo is on a distinguished road
Default

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!
Reply With Quote
  #6  
Old 06-18-2015, 05:17 AM
svo svo is offline Appending a mail merge document to a static file Windows 7 64bit Appending a mail merge document to a static file Office 2003
Novice
Appending a mail merge document to a static file
 
Join Date: Jun 2015
Posts: 7
svo is on a distinguished road
Default [SOLVED] Appending a mail merge document to a static file

Hello there!

Since I said I will do a follow up post here that manaes to do what I wanted all along.

  • So to just make the whole situation a bit worse, the document changed a bit to being a static document with 12 pages. After these 12 pages there should follow a mail merge document with 3 x n pages. After that there was another static page.
  • The static document is build like this: first 12 pages, 1 empty page, last static page. On the empty page there is a book mark called "warehouseregister".
  • The mail merge document is layout-wise the same as the static document (page setup, headers, footer etc. all the same)
  • My templating engine calls a method "AfterTemplating" when it is done replacing all the placeholders with field values.

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
  1. open the mail merge document
  2. attach a data source
  3. run the mail merging
  4. save the document
  5. use the bookmark to setup an INCLUDETEXT field that pulls in the mail merged document
  6. reset the section breaks so that the page numbering is not screwed
And here the shortened VBA that handles all this (I do some more stuff like actually generating the datasource on the fly):
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
Reply With Quote
Reply

Tags
includetext, mail merge



Similar Threads
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
Appending a mail merge document to a static file check for duplicate before appending to new file rcVBA Word VBA 4 05-21-2013 11:40 AM
Appending a mail merge document to a static file Split multi-page mail merge document, then name file from letter info. 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft