didijaba
Well-known Member
- Joined
- Nov 26, 2006
- Messages
- 511
Hi,
I'm doing large mail merge with lots of pictures, and I used macropod advices (thanks macropod), but I have problem when I need to send created word document to someone. It has no images. I'm using Office 2016 (Win). Here are my VBA code and formula for placing images. Images, source excel workbook and word template are all in same folder (same path).
Thanks in advance for any advice.
I'm doing large mail merge with lots of pictures, and I used macropod advices (thanks macropod), but I have problem when I need to send created word document to someone. It has no images. I'm using Office 2016 (Win). Here are my VBA code and formula for placing images. Images, source excel workbook and word template are all in same folder (same path).
Thanks in advance for any advice.
Code:
Sub Merge_To_Individual_Files()
'Merges one record at a time to the folder containing the mailmerge main document.
' Sourced from: https://windowssecrets.com/forums/showthread.php/163017-Word-Mailmerge-Tips-amp-Tricks
Application.ScreenUpdating = False
Dim StrFolder As String, StrName As String, MainDoc As Document, i As Long, j As Long
Const StrNoChr As String = """*./\:?|"
Set MainDoc = ActiveDocument
With MainDoc
StrFolder = .Path & Application.PathSeparator
For i = 1 To .MailMerge.DataSource.RecordCount
With .MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
If Trim(.DataFields("FIELD_1")) = "" Then Exit For
'StrFolder = .DataFields("Folder") & Application.PathSeparator
StrName = .DataFields("FIELD_1") & "_" & .DataFields("FIELD_2")
End With
.Execute Pause:=False
End With
For j = 1 To Len(StrNoChr)
StrName = Replace(StrName, Mid(StrNoChr, j, 1), "_")
Next
StrName = Trim(StrName)
With ActiveDocument
MailMergeToDoc
.SaveAs FileName:=StrFolder & StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
.SaveAs FileName:=StrFolder & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
.Close SaveChanges:=False
End With
Next i
End With
Application.ScreenUpdating = True
End Sub
Private Sub MailMergeToDoc()
Application.ScreenUpdating = False
'ActiveDocument.MailMerge.Execute
Dim Fld As Field
For Each Fld In ActiveDocument.Fields
If Fld.Type <> wdFieldHyperlink Then Fld.Unlink
Next
Application.ScreenUpdating = True
End Sub
Last edited: