#1
|
|||
|
|||
Use a the data from a mail merge field
Hey, I was wondering if it would be possible to use the data from a merge field inside of a macro to change the datapath that the doc would be saved in. I'm working on a macro for my office, that merges patient info into a letter, but I was wondering if I can use the data from these fields in a macro to save the file under the name of the patient. Thanks! |
#2
|
||||
|
||||
If this is a mail merge then you might be better using -
http://www.gmayor.com/individual_merge_letters.htm. or http://www.gmayor.com/MergeAndSplit.htm either of which will split a mail merge using data from merge field(s) in the document to name the individual letters. If you are creating single letters using merge data then there are probably better ways to do so than to use mail merge.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
See Send Mailmerge Output to Individual Files in the Mailmerge Tips and Tricks 'Sticky' thread at the top of this forum:
https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Code:
Sub Image_Folder() ' ' ' ' ImageFolder = _ ActiveDocument.MailMerge.DataSource.DataFields("ImageFolder").Value FL = Left(ImageFolder, 1) FName = _ ActiveDocument.MailMerge.DataSource.DataFields("FName").Value LName = _ ActiveDocument.MailMerge.DataSource.DataFields("LName").Value File = LName & ", " & FName NewPath = "Y:\OpenDentImages\" & FL & "\" & ImageFolder & "\" Dim n As Integer Dim FilePath As String n = 0 Do FilePath = "Y:\OpenDentImages\" & FL & "\" & ImageFolder & "\" & File & IIf(n = 0, "", n) & ".doc" n = n + 1 Loop Until Dir(FilePath) = "" ActiveDocument.SaveAs2 FilePath, FileFormat:=wdFormatPDF ActiveDocument.SaveAs2 FilePath, FileFormat:=wdFormatDocumentDefault End Sub But it only seems to work on the actual template, but not after the data has been merged. Is it possible to maybe reference the template for the data instead of the ActiveDocument? Thank you Last edited by macropod; 12-19-2017 at 02:39 PM. Reason: Added code tags |
#5
|
||||
|
||||
You should study the code in the links you've been given.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mail merge how to link mail merge field value to a column heading | dsummers | Mail Merge | 1 | 05-08-2014 02:59 PM |
Mail Merge Empty Data Field | Licos101 | Mail Merge | 2 | 04-10-2014 06:19 AM |
How to ignore a mail merge field if the field is blank | redzan | Mail Merge | 1 | 05-16-2013 08:34 AM |
Merge field source data field | kckay | Mail Merge | 4 | 03-25-2013 11:06 AM |
Mail Merge - If a field is black, take the data from the row below? | mikeprent | Mail Merge | 5 | 01-05-2012 04:52 AM |