Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Mail Merge

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 12-19-2017, 01:12 AM
pttsv pttsv is offline Windows 10 Office 2013
Novice
 
Join Date: Dec 2017
Posts: 2
pttsv is on a distinguished road
Default 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!
Reply With Quote
  #2  
Old 12-19-2017, 06:11 AM
gmayor's Avatar
gmayor gmayor is online now Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,705
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

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)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 12-19-2017, 01:06 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,199
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

See Send Mailmerge Output to Individual Files in the Mailmerge Tips and Tricks 'Sticky' thread at the top of this forum:
http://www.msofficeforums.com/mail-m...ps-tricks.html
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #4  
Old 12-19-2017, 02:34 PM
pttsv pttsv is offline Windows 10 Office 2013
Novice
 
Join Date: Dec 2017
Posts: 2
pttsv is on a distinguished road
Default

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
this is my code so far.
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
Reply With Quote
  #5  
Old 12-19-2017, 02:40 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,199
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

You should study the code in the links you've been given.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


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


All times are GMT -7. The time now is 07:12 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft