

#Create form letter in word from excel data pdf#
To save the file in pdf format use cDir & NewFileName, _ ObjMMMD.Close savechanges:=wdDoNotSaveChangesĬells(r, 7).Value = "Letter Generated Already" With objMMMD.MailMerge 'With ActiveDocument.MailMerge MailMerge.OpenDataSource Name:=cDir + ThisFileName, sqlstatement:="SELECT * FROM `Data$`" ' Set this as required

' Set to True if you want to see the Word Doc flash past during construction Set objWord = CreateObject("Word.Application") Set objWord = GetObject(, "Word.Application") NewFileName = "Offer Letter - " & EmployeeName & ".docx" 'This is the New 07/10 Word Documents File Name, Change as req'd"ĬDir = ActiveWorkbook.path + "\" 'Change if appropriate If Cells(r, 7).Value = "Letter Generated Already" Then GoTo nextrowĮmployeeName = Sheets("Data").Cells(r, 2).ValueĬonst WTempName = "letter.docx" 'This is the 07/10 Word Templates name, Change as req'd Lastrow = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row Row G: Shows the status (if the letter is generated it shows "Letter Generated Already" after running the macro or it shows blank if it is new record entered.Īlso how can I save the output (merged file) also in PDF other than DOC file so the merged files will be in two formats one in DOC and the other one in PDF formats? Sub MergeMe() Example: if my Excel has 5 Employee details I am able to save the 5 individual merged files on each employee name, however the merged data if of the first employee who is in Row 2. The problem is the output in all the merged files the output is same as the first row. And every time it runs the file for one person it will give the status as Letter Already Generate so that it wont duplicate any Employee records. I have run mail-merge automatically and save individual files as per the Employee name. I have Employee data in Excel and I can generate any Employee letter using that Data and can save the individual Employee letter as per the Employee name. I created a macro in Excel where I can mail-merge data from Excel into Word Letter Template and save the individual files in the folder.
