Fix: Output PDFs Missing Embedded Photos or Signatures
Prove whether each required photo or signature is linked or embedded, repair only explicitly tagged objects in a working DOCX copy, then reopen that copy before exporting and reviewing the PDF.
Quick answer: confirm the image is truly embedded before PDF export
A picture can look correct in Word because the document contains a cached linked result. Save the source DOCX, create a separate working copy, verify every required image file, update and break only the approved picture links, save and reopen the copy, and export the PDF from that verified document.
Identify the required object → verify its source → embed it in a working copy → save → close → reopen → confirm no tagged links remain → export PDF → inspect the actual pages.
Match the symptom to the likely object problem
Word shows the image only on one computer
The document probably depends on a local or mapped-drive source that is unavailable elsewhere.
The PDF has a blank image area
A linked result may not have updated, or the picture object may be hidden, outside the page, or behind another shape.
Body photos work but a signature fails
The signature may be a floating shape in a header or footer rather than an inline picture in the main story.
Only one template fails
Compare wrapping, anchors, crop, page position, object type, and the exact Word container used by the failing template.
DOCX and PDF both miss the image
Fix the insertion step, tag, source path, permissions, or unsupported object before investigating PDF export.
Mail Merge shows the same image for every record
That problem begins earlier in the record-specific merge lifecycle. Use the separate Mail Merge export guide instead.
Define an explicit contract for required images
In Word, open the object’s Alt Text pane and put one exact value in its Description. The VBA helper ignores every image that does not carry one of these tags.
EMBED_PHOTO
Use for a required case photo, evidence image, portrait, product image, or other document-specific picture that must survive independently of its source folder.
EMBED_SIGNATURE
Use only for an approved signature-image asset. The tag controls embedding, not authorization, identity, or release.
Supported object types
The example supports inline pictures and floating pictures, whether already embedded or linked. A tagged group, OLE object, icon, signature line, or other shape type stops the run.
Supported source files
Linked files must use absolute local or UNC paths and PNG, JPG, or JPEG extensions. Wildcards, URLs, empty files, and missing files are rejected.
Prove the fix manually before automating it
Save a disposable DOCX copy
Do not test destructive link changes on the only reviewed source document. Keep the original closed or unchanged.
Inspect the actual object
Check whether it is inline or floating, its Alt Text, wrapping, anchor, layer order, crop, and location in body, header, footer, or text box.
Reinsert one controlled image
Use a small PNG or JPEG from a stable local path, insert it as a picture, save, close, reopen, and export.
Remove source access
Open the tested DOCX copy without access to the original image folder. If the picture disappears, it was not independently embedded.
Repair the export through six controlled stages
1. Save the source DOCX
The example refuses an unsaved document or pending changes so its filesystem copy matches the reviewed Word state.
2. Create an isolated run folder
The original remains open and untouched. The macro copies it into Working and reserves a separate Completed folder.
3. Find only tagged images
Inline pictures are checked across Word story ranges. Floating pictures are checked in the main document, headers, and footers.
4. Verify and break links
Each linked source must be an allowed nonempty file. Word updates the link, saves the picture with the document, then breaks the link.
5. Save, reopen, verify, and export
The working DOCX is saved and closed, then reopened read-only to verify the tagged count and absence of tagged links. Only the verified reopened document is exported to PDF.
6. Commit and inspect
The working pair moves into Completed. A person still checks identity, placement, crop, visibility, and authorization.
Free Word VBA helper: embed tagged images before PDF export
Store this macro in a trusted global template or add-in, open the saved target DOCX, and run EmbedTaggedImagesAndExportVerifiedPdf. It never edits the active source document and never deletes retained evidence after an error.
Explicit scope
Only EMBED_PHOTO and EMBED_SIGNATURE objects are processed. The helper does not inspect every image: untagged images and links remain unchanged.
Broad Word coverage
The code checks inline pictures through story ranges and floating pictures in the main document, headers, and footers.
Source validation
Linked paths must be absolute PNG/JPG/JPEG files without wildcards, and every file must exist with nonzero size.
Working-copy repair
The saved source is copied to a unique run folder. Link updates and link breaking occur only in that copy.
Reopen verification
After saving, the DOCX closes and reopens read-only. Tagged count must match and no tagged linked or unsupported object may remain before PDF export.
Honest PDF boundary
The code confirms a nonempty PDF was created. It cannot inspect visual placement or prove that the pictured person or signature asset is correct.
Option Explicit
Private Const WORD_EXPORT_FORMAT_PDF As Long = 17
Private Const WORD_EXPORT_OPTIMIZE_FOR_PRINT As Long = 0
Private Const WORD_DO_NOT_SAVE_CHANGES As Long = 0
Private Const WORD_ALERTS_NONE As Long = 0
Private Const WORD_INLINE_PICTURE As Long = 3
Private Const WORD_INLINE_LINKED_PICTURE As Long = 4
Private Const OFFICE_LINKED_PICTURE As Long = 11
Private Const OFFICE_PICTURE As Long = 13
Private Const PHOTO_TAG As String = "EMBED_PHOTO"
Private Const SIGNATURE_TAG As String = "EMBED_SIGNATURE"
Public Sub EmbedTaggedImagesAndExportVerifiedPdf()
Dim sourceDoc As Document
Dim workingDoc As Document
Dim fso As Object
Dim sourcePath As String
Dim sourceName As String
Dim baseName As String
Dim outputRoot As String
Dim runFolder As String
Dim workingFolder As String
Dim completedFolder As String
Dim workingDocxPath As String
Dim workingPdfPath As String
Dim finalDocxPath As String
Dim finalPdfPath As String
Dim taggedBefore As Long
Dim linksBroken As Long
Dim taggedAfter As Long
Dim linkedAfter As Long
Dim unsupportedAfter As Long
Dim previousScreenUpdating As Boolean
Dim previousDisplayAlerts As Long
Dim appStateCaptured As Boolean
Dim currentStep As String
Dim errorNumber As Long
Dim errorDescription As String
On Error GoTo CleanFail
Set sourceDoc = ActiveDocument
previousScreenUpdating = Application.ScreenUpdating
previousDisplayAlerts = Application.DisplayAlerts
appStateCaptured = True
Application.ScreenUpdating = False
Application.DisplayAlerts = WORD_ALERTS_NONE
currentStep = "checking the source Word document"
If Len(sourceDoc.Path) = 0 Then
Err.Raise vbObjectError + 4700, , _
"Save the source document as DOCX before running the macro."
End If
If Not sourceDoc.Saved Then
Err.Raise vbObjectError + 4701, , _
"Save all source-document changes before running the macro."
End If
sourcePath = sourceDoc.FullName
sourceName = sourceDoc.Name
If LCase$(Right$(sourceName, 5)) <> ".docx" Then
Err.Raise vbObjectError + 4702, , _
"The source document must use the .docx format."
End If
baseName = Left$(sourceName, Len(sourceName) - 5)
ValidateFileStem baseName
Set fso = CreateObject("Scripting.FileSystemObject")
RequireExistingFile sourcePath, "source DOCX"
outputRoot = JoinPath(sourceDoc.Path, "VerifiedPdfExports")
EnsureFolder outputRoot
runFolder = CreateRunFolder(fso, outputRoot)
workingFolder = JoinPath(runFolder, "Working")
completedFolder = JoinPath(runFolder, "Completed")
fso.CreateFolder workingFolder
fso.CreateFolder completedFolder
workingDocxPath = JoinPath(workingFolder, baseName & _
"_embedded.docx")
workingPdfPath = JoinPath(workingFolder, baseName & _
"_embedded.pdf")
finalDocxPath = JoinPath(completedFolder, baseName & _
"_embedded.docx")
finalPdfPath = JoinPath(completedFolder, baseName & _
"_embedded.pdf")
currentStep = "copying the saved source document"
fso.CopyFile sourcePath, workingDocxPath, False
RequireNonemptyFile workingDocxPath, "working DOCX copy"
currentStep = "opening the working DOCX copy"
Set workingDoc = Documents.Open( _
FileName:=workingDocxPath, _
ConfirmConversions:=False, _
ReadOnly:=False, _
AddToRecentFiles:=False, _
Visible:=False)
currentStep = "embedding tagged photos and signatures"
EmbedTaggedImages workingDoc, taggedBefore, linksBroken
If taggedBefore = 0 Then
Err.Raise vbObjectError + 4703, , _
"No objects use Alt Text EMBED_PHOTO or EMBED_SIGNATURE."
End If
workingDoc.Save
currentStep = "closing the saved embedded DOCX"
workingDoc.Close WORD_DO_NOT_SAVE_CHANGES
Set workingDoc = Nothing
RequireNonemptyFile workingDocxPath, "embedded working DOCX"
currentStep = "reopening and auditing the embedded DOCX"
Set workingDoc = Documents.Open( _
FileName:=workingDocxPath, _
ConfirmConversions:=False, _
ReadOnly:=True, _
AddToRecentFiles:=False, _
Visible:=False)
AuditTaggedImages workingDoc, taggedAfter, linkedAfter, _
unsupportedAfter
If taggedAfter <> taggedBefore Then
Err.Raise vbObjectError + 4704, , _
"Tagged image count changed after save and reopen."
End If
If linkedAfter <> 0 Then
Err.Raise vbObjectError + 4705, , _
"A tagged image is still linked after save and reopen."
End If
If unsupportedAfter <> 0 Then
Err.Raise vbObjectError + 4706, , _
"A tagged object has an unsupported Word shape type."
End If
currentStep = "exporting PDF from the verified reopened DOCX"
RequireTargetAbsent workingPdfPath
workingDoc.ExportAsFixedFormat workingPdfPath, _
WORD_EXPORT_FORMAT_PDF, False, WORD_EXPORT_OPTIMIZE_FOR_PRINT
workingDoc.Close WORD_DO_NOT_SAVE_CHANGES
Set workingDoc = Nothing
RequireNonemptyFile workingPdfPath, "working PDF"
currentStep = "committing the verified DOCX and PDF pair"
RequireTargetAbsent finalDocxPath
RequireTargetAbsent finalPdfPath
Name workingDocxPath As finalDocxPath
Name workingPdfPath As finalPdfPath
RemoveEmptyFolder workingFolder
Application.DisplayAlerts = previousDisplayAlerts
Application.ScreenUpdating = previousScreenUpdating
appStateCaptured = False
MsgBox "Verified export pair created." & vbCrLf & _
"Tagged objects: " & taggedBefore & vbCrLf & _
"Links embedded: " & linksBroken & vbCrLf & _
"DOCX: " & finalDocxPath & vbCrLf & _
"PDF: " & finalPdfPath & vbCrLf & vbCrLf & _
"Open the PDF and visually confirm every photo and signature.", _
vbInformation
CleanExit:
On Error Resume Next
If Not workingDoc Is Nothing Then _
workingDoc.Close WORD_DO_NOT_SAVE_CHANGES
If appStateCaptured Then
Application.DisplayAlerts = previousDisplayAlerts
Application.ScreenUpdating = previousScreenUpdating
End If
Set workingDoc = Nothing
Set sourceDoc = Nothing
Set fso = Nothing
On Error GoTo 0
Exit Sub
CleanFail:
errorNumber = Err.Number
errorDescription = Err.Description
On Error Resume Next
If Not workingDoc Is Nothing Then _
workingDoc.Close WORD_DO_NOT_SAVE_CHANGES
If appStateCaptured Then
Application.DisplayAlerts = previousDisplayAlerts
Application.ScreenUpdating = previousScreenUpdating
End If
Set workingDoc = Nothing
Set sourceDoc = Nothing
Set fso = Nothing
On Error GoTo 0
MsgBox "Export stopped while " & currentStep & "." & vbCrLf & _
"Error " & errorNumber & ": " & errorDescription & vbCrLf & _
IIf(Len(runFolder) > 0, _
"Inspect the retained run folder: " & runFolder, _
"No run folder was created.") & vbCrLf & _
"The original DOCX was not modified and existing output was not deleted.", _
vbCritical
End Sub
Private Sub EmbedTaggedImages(ByVal doc As Document, _
ByRef taggedCount As Long, _
ByRef linksBroken As Long)
Dim rootStory As Range
Dim currentStory As Range
Dim inlineItem As InlineShape
Dim shapeItem As Shape
Dim sectionItem As Section
Dim headerFooterIndex As Long
Dim headerFooterItem As HeaderFooter
Dim uniqueShapes As Object
Dim shapeKey As Variant
Set uniqueShapes = CreateObject("Scripting.Dictionary")
uniqueShapes.CompareMode = vbBinaryCompare
For Each rootStory In doc.StoryRanges
Set currentStory = rootStory
Do While Not currentStory Is Nothing
For Each inlineItem In currentStory.InlineShapes
EmbedTaggedInlineShape inlineItem, taggedCount, linksBroken
Next inlineItem
Set currentStory = currentStory.NextStoryRange
Loop
Next rootStory
For Each shapeItem In doc.Shapes
AddUniqueShape shapeItem, uniqueShapes
Next shapeItem
For Each sectionItem In doc.Sections
For headerFooterIndex = 1 To 3
Set headerFooterItem = sectionItem.Headers(headerFooterIndex)
If headerFooterItem.Exists Then
For Each shapeItem In headerFooterItem.Shapes
AddUniqueShape shapeItem, uniqueShapes
Next shapeItem
End If
Set headerFooterItem = sectionItem.Footers(headerFooterIndex)
If headerFooterItem.Exists Then
For Each shapeItem In headerFooterItem.Shapes
AddUniqueShape shapeItem, uniqueShapes
Next shapeItem
End If
Next headerFooterIndex
Next sectionItem
For Each shapeKey In uniqueShapes.Keys
Set shapeItem = uniqueShapes.Item(shapeKey)
EmbedTaggedShape shapeItem, taggedCount, linksBroken
Next shapeKey
End Sub
Private Sub EmbedTaggedInlineShape(ByVal imageItem As InlineShape, _
ByRef taggedCount As Long, _
ByRef linksBroken As Long)
Dim imageTag As String
Dim sourcePath As String
Dim linkItem As LinkFormat
imageTag = imageItem.AlternativeText
If Not IsRequiredImageTag(imageTag) Then Exit Sub
taggedCount = taggedCount + 1
Select Case imageItem.Type
Case WORD_INLINE_PICTURE
Exit Sub
Case WORD_INLINE_LINKED_PICTURE
Set linkItem = imageItem.LinkFormat
sourcePath = ReadLinkSourceStrict(linkItem, imageTag)
RequireValidImageFile sourcePath, imageTag
linkItem.Update
linkItem.SavePictureWithDocument = True
linkItem.BreakLink
imageItem.AlternativeText = imageTag
If imageItem.Type = WORD_INLINE_LINKED_PICTURE Then
Err.Raise vbObjectError + 4707, , _
"Inline image link was not broken: " & imageTag
End If
linksBroken = linksBroken + 1
Case Else
Err.Raise vbObjectError + 4708, , _
"Tagged inline object is not a supported picture: " & imageTag
End Select
End Sub
Private Sub EmbedTaggedShape(ByVal imageItem As Shape, _
ByRef taggedCount As Long, _
ByRef linksBroken As Long)
Dim imageTag As String
Dim sourcePath As String
Dim linkItem As LinkFormat
imageTag = imageItem.AlternativeText
If Not IsRequiredImageTag(imageTag) Then Exit Sub
taggedCount = taggedCount + 1
Select Case imageItem.Type
Case OFFICE_PICTURE
Exit Sub
Case OFFICE_LINKED_PICTURE
Set linkItem = imageItem.LinkFormat
sourcePath = ReadLinkSourceStrict(linkItem, imageTag)
RequireValidImageFile sourcePath, imageTag
linkItem.Update
linkItem.SavePictureWithDocument = True
linkItem.BreakLink
imageItem.AlternativeText = imageTag
If imageItem.Type = OFFICE_LINKED_PICTURE Then
Err.Raise vbObjectError + 4709, , _
"Floating image link was not broken: " & imageTag
End If
linksBroken = linksBroken + 1
Case Else
Err.Raise vbObjectError + 4710, , _
"Tagged floating object is not a supported picture: " & imageTag
End Select
End Sub
Private Sub AuditTaggedImages(ByVal doc As Document, _
ByRef taggedCount As Long, _
ByRef linkedCount As Long, _
ByRef unsupportedCount As Long)
Dim rootStory As Range
Dim currentStory As Range
Dim inlineItem As InlineShape
Dim shapeItem As Shape
Dim sectionItem As Section
Dim headerFooterIndex As Long
Dim headerFooterItem As HeaderFooter
Dim uniqueShapes As Object
Dim shapeKey As Variant
Set uniqueShapes = CreateObject("Scripting.Dictionary")
uniqueShapes.CompareMode = vbBinaryCompare
For Each rootStory In doc.StoryRanges
Set currentStory = rootStory
Do While Not currentStory Is Nothing
For Each inlineItem In currentStory.InlineShapes
AuditInlineShape inlineItem, taggedCount, _
linkedCount, unsupportedCount
Next inlineItem
Set currentStory = currentStory.NextStoryRange
Loop
Next rootStory
For Each shapeItem In doc.Shapes
AddUniqueShape shapeItem, uniqueShapes
Next shapeItem
For Each sectionItem In doc.Sections
For headerFooterIndex = 1 To 3
Set headerFooterItem = sectionItem.Headers(headerFooterIndex)
If headerFooterItem.Exists Then
For Each shapeItem In headerFooterItem.Shapes
AddUniqueShape shapeItem, uniqueShapes
Next shapeItem
End If
Set headerFooterItem = sectionItem.Footers(headerFooterIndex)
If headerFooterItem.Exists Then
For Each shapeItem In headerFooterItem.Shapes
AddUniqueShape shapeItem, uniqueShapes
Next shapeItem
End If
Next headerFooterIndex
Next sectionItem
For Each shapeKey In uniqueShapes.Keys
Set shapeItem = uniqueShapes.Item(shapeKey)
AuditShape shapeItem, taggedCount, linkedCount, unsupportedCount
Next shapeKey
End Sub
Private Sub AuditInlineShape(ByVal imageItem As InlineShape, _
ByRef taggedCount As Long, _
ByRef linkedCount As Long, _
ByRef unsupportedCount As Long)
If Not IsRequiredImageTag(imageItem.AlternativeText) Then Exit Sub
taggedCount = taggedCount + 1
Select Case imageItem.Type
Case WORD_INLINE_PICTURE
Case WORD_INLINE_LINKED_PICTURE
linkedCount = linkedCount + 1
Case Else
unsupportedCount = unsupportedCount + 1
End Select
End Sub
Private Sub AuditShape(ByVal imageItem As Shape, _
ByRef taggedCount As Long, _
ByRef linkedCount As Long, _
ByRef unsupportedCount As Long)
If Not IsRequiredImageTag(imageItem.AlternativeText) Then Exit Sub
taggedCount = taggedCount + 1
Select Case imageItem.Type
Case OFFICE_PICTURE
Case OFFICE_LINKED_PICTURE
linkedCount = linkedCount + 1
Case Else
unsupportedCount = unsupportedCount + 1
End Select
End Sub
Private Sub AddUniqueShape(ByVal imageItem As Shape, _
ByVal uniqueShapes As Object)
Dim shapeKey As String
shapeKey = CStr(imageItem.ID)
If Not uniqueShapes.Exists(shapeKey) Then
uniqueShapes.Add shapeKey, imageItem
End If
End Sub
Private Function IsRequiredImageTag(ByVal alternativeText As String) As Boolean
IsRequiredImageTag = _
(StrComp(alternativeText, PHOTO_TAG, vbBinaryCompare) = 0 Or _
StrComp(alternativeText, SIGNATURE_TAG, vbBinaryCompare) = 0)
End Function
Private Function ReadLinkSourceStrict(ByVal linkItem As LinkFormat, _
ByVal imageTag As String) As String
On Error GoTo LinkFailed
ReadLinkSourceStrict = linkItem.SourceFullName
If Len(ReadLinkSourceStrict) = 0 Then GoTo LinkFailed
Exit Function
LinkFailed:
Err.Raise vbObjectError + 4711, , _
"Could not read the linked source for tagged image " & imageTag & "."
End Function
Private Sub RequireValidImageFile(ByVal imagePath As String, _
ByVal imageTag As String)
Dim extensionPosition As Long
Dim extensionText As String
If imagePath <> Trim$(imagePath) Then
Err.Raise vbObjectError + 4712, , _
"Linked image path has outer whitespace: " & imageTag
End If
If InStr(1, imagePath, "*", vbBinaryCompare) > 0 Or _
InStr(1, imagePath, "?", vbBinaryCompare) > 0 Then
Err.Raise vbObjectError + 4713, , _
"Linked image path contains a wildcard: " & imageTag
End If
If Not IsAbsolutePath(imagePath) Then
Err.Raise vbObjectError + 4714, , _
"Linked image path must be an absolute UNC or drive path: " & _
imageTag
End If
extensionPosition = InStrRev(imagePath, ".")
If extensionPosition <= 1 Then
Err.Raise vbObjectError + 4715, , _
"Linked image needs a PNG, JPG, or JPEG extension: " & imageTag
End If
extensionText = UCase$(Mid$(imagePath, extensionPosition + 1))
If extensionText <> "PNG" And extensionText <> "JPG" And _
extensionText <> "JPEG" Then
Err.Raise vbObjectError + 4716, , _
"Linked image must use PNG, JPG, or JPEG: " & imageTag
End If
RequireNonemptyFile imagePath, "linked image " & imageTag
End Sub
Private Function IsAbsolutePath(ByVal pathText As String) As Boolean
If Len(pathText) >= 2 Then
If Left$(pathText, 2) = "\\" Then
IsAbsolutePath = True
Exit Function
End If
End If
If Len(pathText) >= 3 Then
If Mid$(pathText, 2, 2) = ":\" Then IsAbsolutePath = True
End If
End Function
Private Sub ValidateFileStem(ByVal fileStem As String)
Dim invalidCharacters As Variant
Dim invalidCharacter As Variant
Dim baseName As String
If Len(fileStem) = 0 Or Len(fileStem) > 120 Then
Err.Raise vbObjectError + 4717, , _
"The source filename stem must contain 1 to 120 characters."
End If
invalidCharacters = Array("<", ">", ":", Chr$(34), "/", _
"\", "|", "?", "*")
For Each invalidCharacter In invalidCharacters
If InStr(1, fileStem, CStr(invalidCharacter), _
vbBinaryCompare) > 0 Then
Err.Raise vbObjectError + 4718, , _
"The source filename contains a forbidden Windows character."
End If
Next invalidCharacter
If ContainsControlCharacter(fileStem) Then
Err.Raise vbObjectError + 4719, , _
"The source filename contains a control character."
End If
If Right$(fileStem, 1) = "." Or Right$(fileStem, 1) = " " Then
Err.Raise vbObjectError + 4720, , _
"The source filename cannot end with a period or space."
End If
baseName = fileStem
If InStr(1, baseName, ".", vbBinaryCompare) > 0 Then
baseName = Left$(baseName, InStr(1, baseName, ".", _
vbBinaryCompare) - 1)
End If
If IsReservedWindowsName(baseName) Then
Err.Raise vbObjectError + 4721, , _
"The source filename uses a reserved Windows name."
End If
End Sub
Private Function CreateRunFolder(ByVal fso As Object, _
ByVal outputRoot As String) As String
Dim runId As String
Dim attempt As Long
Dim candidate As String
runId = Format$(Now, "yyyymmdd_hhnnss") & "_" & _
Format$(CLng(Timer * 100), "00000000")
For attempt = 0 To 99
candidate = JoinPath(outputRoot, "Run_" & runId & _
IIf(attempt = 0, "", "_" & Format$(attempt, "00")))
If Not fso.FolderExists(candidate) Then
fso.CreateFolder candidate
CreateRunFolder = candidate
Exit Function
End If
Next attempt
Err.Raise vbObjectError + 4722, , _
"Could not create a unique output run folder."
End Function
Private Sub EnsureFolder(ByVal folderPath As String)
If FolderExistsStrict(folderPath) Then Exit Sub
On Error GoTo CreateFailed
MkDir folderPath
If Not FolderExistsStrict(folderPath) Then GoTo CreateFailed
Exit Sub
CreateFailed:
Err.Raise vbObjectError + 4723, , _
"Could not create folder: " & folderPath & ". " & Err.Description
End Sub
Private Sub RequireTargetAbsent(ByVal filePath As String)
If FileExistsStrict(filePath) Then
Err.Raise vbObjectError + 4724, , _
"Output already exists and will not be overwritten: " & filePath
End If
End Sub
Private Sub RequireExistingFile(ByVal filePath As String, _
ByVal fileLabel As String)
If Not FileExistsStrict(filePath) Then
Err.Raise vbObjectError + 4725, , _
fileLabel & " was not found: " & filePath
End If
End Sub
Private Sub RequireNonemptyFile(ByVal filePath As String, _
ByVal fileLabel As String)
RequireExistingFile filePath, fileLabel
If FileLen(filePath) <= 0 Then
Err.Raise vbObjectError + 4726, , _
fileLabel & " is empty: " & filePath
End If
End Sub
Private Function FileExistsStrict(ByVal filePath As String) As Boolean
On Error GoTo CheckFailed
FileExistsStrict = (Len(Dir$(filePath, vbNormal Or vbHidden Or _
vbSystem Or vbReadOnly Or vbArchive)) > 0)
Exit Function
CheckFailed:
Err.Raise vbObjectError + 4727, , _
"Could not check file path: " & filePath & ". " & Err.Description
End Function
Private Function FolderExistsStrict(ByVal folderPath As String) As Boolean
Dim attributes As Long
On Error GoTo NotFound
attributes = GetAttr(folderPath)
FolderExistsStrict = ((attributes And vbDirectory) = vbDirectory)
Exit Function
NotFound:
If Err.Number = 53 Or Err.Number = 76 Then
Err.Clear
FolderExistsStrict = False
Else
Err.Raise vbObjectError + 4728, , _
"Could not check folder path: " & folderPath & ". " & _
Err.Description
End If
End Function
Private Sub RemoveEmptyFolder(ByVal folderPath As String)
If Len(folderPath) = 0 Then Exit Sub
If Not FolderExistsStrict(folderPath) Then Exit Sub
If Len(Dir$(JoinPath(folderPath, "*"), vbNormal Or vbHidden Or _
vbSystem Or vbReadOnly Or vbArchive Or vbDirectory)) > 0 Then
Exit Sub
End If
RmDir folderPath
End Sub
Private Function JoinPath(ByVal parentPath As String, _
ByVal childName As String) As String
If Right$(parentPath, 1) = "\" Then
JoinPath = parentPath & childName
Else
JoinPath = parentPath & "\" & childName
End If
End Function
Private Function ContainsControlCharacter(ByVal valueText As String) As Boolean
Dim characterIndex As Long
Dim characterCode As Long
For characterIndex = 1 To Len(valueText)
characterCode = AscW(Mid$(valueText, characterIndex, 1))
If characterCode >= 0 And characterCode <= 31 Then
ContainsControlCharacter = True
Exit Function
End If
Next characterIndex
End Function
Private Function IsReservedWindowsName(ByVal baseName As String) As Boolean
Dim upperName As String
Dim prefix As String
Dim finalCharacter As String
upperName = UCase$(baseName)
Select Case upperName
Case "CON", "PRN", "AUX", "NUL", _
"COM1", "COM2", "COM3", "COM4", "COM5", _
"COM6", "COM7", "COM8", "COM9", _
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", _
"LPT6", "LPT7", "LPT8", "LPT9"
IsReservedWindowsName = True
Exit Function
End Select
If Len(upperName) = 4 Then
prefix = Left$(upperName, 3)
finalCharacter = Right$(upperName, 1)
If (prefix = "COM" Or prefix = "LPT") And _
(finalCharacter = ChrW$(&HB9) Or _
finalCharacter = ChrW$(&HB2) Or _
finalCharacter = ChrW$(&HB3)) Then
IsReservedWindowsName = True
End If
End If
End FunctionMicrosoft documents the picture-link properties available through LinkFormat, explains that BreakLink disconnects the source after preserving the current result, and provides the PDF options for ExportAsFixedFormat.
Know what this repair cannot guarantee
No PDF image recognition
A nonempty PDF can still contain a blank, cropped, hidden, or wrong image. Visual review remains mandatory.
No authenticity proof
Extension, existence, and size do not prove that the file is a valid image, unedited, correctly identified, or appropriate for the document.
No signature authorization
Embedding preserves pixels. It does not prove identity, intent, consent, certificate status, or permission to use the asset.
No unsupported-object conversion
Tagged groups, OLE objects, signature-line controls, and non-picture shapes stop the macro instead of being silently converted.
No atomic output pair
DOCX and PDF move separately. A failure between moves can leave one final file and one working file for manual reconciliation.
No Word-build guarantee
Printer drivers, fonts, security policy, protection, corruption, and Word version can still affect export behavior.
Run a six-object export pilot
Main-story inline photo
Use a visibly labeled image and confirm it stays embedded after the source folder is unavailable.
Main-story floating photo
Test wrapping, anchor, crop, layer order, and page position in both DOCX and PDF.
Header logo or signature
Confirm the correct header type and every section where the image should appear.
Footer image
Test primary, first-page, and even-page footer configurations used by the real template.
Missing-source rejection
Break a disposable linked path and confirm the macro stops before committing an output pair.
Unauthorized signature test
Confirm the operating process blocks an unapproved signature asset even though the code could embed its pixels.
Approve only when every tagged object remains visible after DOCX reopen, the source folder is unavailable, the PDF matches the intended layout, and the required authorization record exists for every signature image.
Use the DocxForge Pro module that matches the document architecture
DocxForge Pro provides local Word-template generation workflows. It does not authenticate image content or signature authorization, and final DOCX/PDF review still belongs to the operator.
Contractor: one case, several different documents
Review one case dataset and its approved assets, then create several different documents for that case from different Word templates. Use it for a coordinated case pack.
Factory: many rows, one standard template
Apply one standard Word template to many independent Excel rows. Every selected row creates its own document for the same repeatable document type.
The product does not authenticate image content, approve signature use, repair every arbitrary Word object, or replace visual review. Test photo and signature slots with your own templates, Confirm the chosen assets, output filenames, page layout, DOCX files, PDFs, and release authorization before distribution.
Contractor: approved assets for one case
Review one case and its shared assets, then choose the different documents required for the case.


Factory: row-specific assets in a standard batch
Review the independent Excel rows, then apply one tested Word template to the selected batch.


Frequently asked questions
Why can an image appear in Word but disappear from the PDF?
Word may be showing a cached linked picture rather than an independent embedded copy. If the source file is unavailable or the link cannot update during export, the PDF can contain a blank or stale result.
Does the macro process every image in the document?
No. It processes only pictures whose Alt Text is exactly EMBED_PHOTO or EMBED_SIGNATURE. This prevents the macro from breaking unrelated links or changing decorative objects without an explicit contract.
Does an embedded signature image prove authorization?
No. A signature image is not a digital signature, identity proof, consent record, or evidence that the named person authorized its use. Approve access and release separately.
Does the VBA prove that the image appears correctly in the PDF?
No. It verifies the source file, breaks tagged links in a working copy, reopens the DOCX, confirms the tagged objects are embedded, and checks that the PDF exists and is nonempty. A person must still inspect placement, cropping, identity, and visibility in the PDF.
What if a truly embedded image is still missing after export?
Check whether it is behind another object, outside the page, hidden by wrapping or crop settings, stored in an unsupported object type, damaged, or affected by a specific Word build. Reinsert a controlled PNG or JPEG and test a minimal document.
Where does DocxForge Pro fit?
Contractor creates several different documents for one reviewed case from different Word templates. Factory applies one standard Word template to many independent Excel rows and creates a separate output for each selected row. Both still require tested image slots, authorized signature assets, and final DOCX/PDF review.