Fixes & Troubleshooting

Fix: Mail Merge Alternatives When You Need Conditional Sections

Choose the smallest reliable method for conditional Word content: an IF rule for short text, prepared Excel values for simple blocks, or a tested VBA workflow when complete clauses must be inserted or removed before DOCX and PDF output.

Word IF rules
Whole-block cleanup
Reviewed DOCX + PDF
Local Word workflow
Word mail merge supports conditional rules. The difficult case is a complete formatted block whose heading, body, spacing, and final paragraph mark must appear or disappear together.

Quick answer: use the smallest tool that controls the whole block

Word mail merge does support conditional rules. The failure usually appears when the condition controls more than a short phrase: a heading, several paragraphs, a table, an image, or the spacing around an optional clause.

One short phrase

Use Word's If...Then...Else rule. It is the simplest option when both outcomes are short and share the same paragraph formatting.

One prepared text block

Calculate the final wording in Excel and merge one document-ready column. This keeps the Word field simple, but Excel must own the text decision.

One complete optional clause

Use a tested bookmark or content-control workflow that can keep or delete the entire formatted region before saving the document.

A recurring production workflow

Choose a generator only after the process matches its model: many rows and one template, or one case and several different documents.

Do not replace mail merge automatically

Microsoft documents an If...Then...Else rule for conditional text. Keep it when it remains readable and the output previews correctly. Move to another method when the rule must control layout, not merely wording.

Diagnose the failure before changing tools

The visible symptom tells you whether the problem is the condition, the data, or the Word structure around it.

Wrong text appears

The comparison value does not match the source exactly. Normalize the Excel flag and test a small recipient set.

A blank line remains

The field or bookmark covers text but not the paragraph mark. The condition must own the complete optional paragraph.

Formatting changes

The replacement range contains mixed styles or the inserted value adopts a neighboring style. Use a uniform placeholder style or retain the formatted block in Word.

Nested rules are unreadable

The business decision is too complex for field codes. Resolve the decision in Excel or in a maintainable VBA procedure.

Templates keep multiplying

Teams are encoding rules in filenames. Keep separate templates only when the layouts are genuinely different and controlled as separate releases.

DOCX and PDF disagree

The document repaginates during export. Review both formats with the longest included text and every optional-block combination.

Choose the method by the condition, not the brand

Start with the least complicated option that can be tested by a reviewer. Microsoft explains the available mail merge rules, including If...Then...Else.

Word IF field

Best for short inline alternatives such as domestic versus international wording. Avoid deep nesting.

Prepared Excel column

Best when Excel can return the exact final text and Word only needs to place it in one styled location.

Separate controlled templates

Best when layouts, tables, or legal structures are truly different. Do not create variants for minor wording changes.

Bookmark-driven VBA

Best for a modest local batch where complete optional blocks must be kept or deleted before DOCX and PDF are saved.

Factory workflow

Best for many Excel rows sent through one standard Word template, one output set per row.

Contractor workflow

Best for one case that needs several different documents from different Word templates.

Set up the Office-only workaround

Save the Excel file as an Excel Macro-Enabled Workbook (.xlsm). Create a sheet named Data, place the exact headers below in row 1, and store display-ready dates and optional text as text.

Required Excel columns A–H

A — DocumentID; B — ClientName; C — ContractDateDisplay; D — IncludeWarranty; E — WarrantyText; F — IncludeAppendix; G — AppendixText; H — Status.

Required Word bookmarks

ClientName, ContractDate, WarrantyBlock, WarrantyText, AppendixBlock, and AppendixText.

Use exact flags

Columns D and F must contain exactly YES or NO. The macro rejects ambiguous values.

Use document-ready text

Format DocumentID and ContractDateDisplay as Text before entering or importing values when leading zeros or exact date wording matter.

Mark the whole block

Each outer block bookmark must include the complete optional section and its final paragraph mark, but not the next required paragraph or a section break. The inner text bookmark sits inside that block.

Control the batch

Only rows whose Status is READY are processed. Other rows remain untouched for review.

Folder layout

Place the template at Templates\ConditionalContractTemplate.docx beside the workbook. The macro creates GeneratedConditionalDocs beside the workbook and saves one DOCX/PDF pair per READY row.

Free VBA workaround: insert or remove complete sections

This Excel VBA example snapshots A–H, validates every READY row and output name before Word starts, opens a fresh copy of one template per row, and either fills or deletes the optional bookmarked blocks.

Option Explicit

Private Const wdFormatXMLDocument As Long = 12
Private Const wdExportFormatPDF As Long = 17
Private Const FILE_ATTRIBUTES As Long = 7
Private Const FOLDER_ATTRIBUTES As Long = 22

Public Sub GenerateConditionalDocuments()
    Const DATA_SHEET As String = "Data"
    Const TEMPLATE_FILE As String = "ConditionalContractTemplate.docx"
    Const OUTPUT_FOLDER_NAME As String = "GeneratedConditionalDocs"

    Dim ws As Worksheet
    Dim lastCell As Range
    Dim data As Variant
    Dim nameKeys As Object
    Dim wdApp As Object
    Dim wdDoc As Object
    Dim templateFolder As String
    Dim templatePath As String
    Dim outputFolder As String
    Dim runFolder As String
    Dim docxPath As String
    Dim pdfPath As String
    Dim tempDocxPath As String
    Dim tempPdfPath As String
    Dim documentId As String
    Dim clientName As String
    Dim contractDateText As String
    Dim warrantyText As String
    Dim appendixText As String
    Dim statusText As String
    Dim baseName As String
    Dim includeWarranty As Boolean
    Dim includeAppendix As Boolean
    Dim lastRow As Long
    Dim dataRow As Long
    Dim rowNumber As Long
    Dim readyCount As Long
    Dim generatedCount As Long
    Dim currentStep As String
    Dim errorNumber As Long
    Dim errorDescription As String

    On Error GoTo CleanFail

    currentStep = "checking the saved workbook location"
    If Len(ThisWorkbook.Path) = 0 Then
        Err.Raise vbObjectError + 2600, , _
            "Save the macro-enabled workbook before running this macro."
    End If

    currentStep = "building the template and output paths"
    templateFolder = JoinPath(ThisWorkbook.Path, "Templates")
    templatePath = JoinPath(templateFolder, TEMPLATE_FILE)
    outputFolder = JoinPath(ThisWorkbook.Path, OUTPUT_FOLDER_NAME)

    If Len(Dir$(templatePath, FILE_ATTRIBUTES)) = 0 Then
        Err.Raise vbObjectError + 2601, , _
            "Template not found: " & templatePath
    End If
    If Len(Dir$(outputFolder, FOLDER_ATTRIBUTES)) = 0 Then
        MkDir outputFolder
    End If

    currentStep = "opening the Data worksheet"
    Set ws = ThisWorkbook.Worksheets(DATA_SHEET)
    ValidateHeaders ws

    currentStep = "finding the final data row"
    Set lastCell = ws.Range("A:H").Find( _
        What:="*", _
        After:=ws.Range("A1"), _
        LookIn:=xlFormulas, _
        LookAt:=xlPart, _
        SearchOrder:=xlByRows, _
        SearchDirection:=xlPrevious, _
        MatchCase:=False)
    If lastCell Is Nothing Then
        Err.Raise vbObjectError + 2602, , _
            "No data rows were found on the Data worksheet."
    End If
    If lastCell.Row < 2 Then
        Err.Raise vbObjectError + 2602, , _
            "No data rows were found on the Data worksheet."
    End If
    lastRow = lastCell.Row
    data = ws.Range("A2:H" & lastRow).Value2

    currentStep = "preflighting READY rows"
    Set nameKeys = CreateObject("Scripting.Dictionary")
    nameKeys.CompareMode = vbTextCompare

    For dataRow = 1 To UBound(data, 1)
        rowNumber = dataRow + 1
        statusText = ReadOptionalText(data(dataRow, 8), "H" & rowNumber)

        If StrComp(statusText, "READY", vbTextCompare) = 0 Then
            readyCount = readyCount + 1
            documentId = ReadRequiredText( _
                data(dataRow, 1), "DocumentID", "A" & rowNumber)
            clientName = ReadRequiredText( _
                data(dataRow, 2), "ClientName", "B" & rowNumber)
            contractDateText = ReadRequiredText( _
                data(dataRow, 3), "ContractDateDisplay", _
                "C" & rowNumber)
            includeWarranty = ReadYesNo( _
                data(dataRow, 4), "D" & rowNumber)
            warrantyText = ReadOptionalText( _
                data(dataRow, 5), "E" & rowNumber)
            includeAppendix = ReadYesNo( _
                data(dataRow, 6), "F" & rowNumber)
            appendixText = ReadOptionalText( _
                data(dataRow, 7), "G" & rowNumber)

            If includeWarranty And Len(warrantyText) = 0 Then
                RaiseCellError ws, "E" & rowNumber, _
                    "WarrantyText is required when IncludeWarranty is YES."
            End If
            If includeAppendix And Len(appendixText) = 0 Then
                RaiseCellError ws, "G" & rowNumber, _
                    "AppendixText is required when IncludeAppendix is YES."
            End If

            baseName = "Conditional_" & CleanFileName(documentId)
            docxPath = JoinPath(outputFolder, baseName & ".docx")
            pdfPath = JoinPath(outputFolder, baseName & ".pdf")

            If nameKeys.Exists(baseName) Then
                Err.Raise vbObjectError + 2603, , _
                    "Duplicate output name after cleaning: " & baseName & _
                    " (Excel row " & rowNumber & ")."
            End If
            nameKeys.Add baseName, rowNumber

            If Len(Dir$(docxPath, FILE_ATTRIBUTES)) > 0 Or _
               Len(Dir$(pdfPath, FILE_ATTRIBUTES)) > 0 Then
                Err.Raise vbObjectError + 2604, , _
                    "Output already exists for Excel row " & _
                    rowNumber & ": " & baseName
            End If
        End If
    Next dataRow

    If readyCount = 0 Then
        Err.Raise vbObjectError + 2605, , _
            "No rows with Status READY were found."
    End If

    currentStep = "creating the run-specific temporary folder"
    runFolder = CreateRunFolder(outputFolder)

    currentStep = "starting Microsoft Word"
    Set wdApp = CreateObject("Word.Application")
    wdApp.Visible = False
    wdApp.ScreenUpdating = False
    wdApp.DisplayAlerts = 0

    For dataRow = 1 To UBound(data, 1)
        rowNumber = dataRow + 1
        statusText = ReadOptionalText(data(dataRow, 8), "H" & rowNumber)

        If StrComp(statusText, "READY", vbTextCompare) = 0 Then
            documentId = ReadRequiredText( _
                data(dataRow, 1), "DocumentID", "A" & rowNumber)
            clientName = ReadRequiredText( _
                data(dataRow, 2), "ClientName", "B" & rowNumber)
            contractDateText = ReadRequiredText( _
                data(dataRow, 3), "ContractDateDisplay", _
                "C" & rowNumber)
            includeWarranty = ReadYesNo( _
                data(dataRow, 4), "D" & rowNumber)
            warrantyText = ReadOptionalText( _
                data(dataRow, 5), "E" & rowNumber)
            includeAppendix = ReadYesNo( _
                data(dataRow, 6), "F" & rowNumber)
            appendixText = ReadOptionalText( _
                data(dataRow, 7), "G" & rowNumber)

            baseName = "Conditional_" & CleanFileName(documentId)
            docxPath = JoinPath(outputFolder, baseName & ".docx")
            pdfPath = JoinPath(outputFolder, baseName & ".pdf")
            tempDocxPath = JoinPath(runFolder, baseName & ".docx")
            tempPdfPath = JoinPath(runFolder, baseName & ".pdf")
            currentStep = "opening the template for Excel row " & rowNumber
            Set wdDoc = wdApp.Documents.Open( _
                templatePath, False, True, False)
            VerifyTemplateBookmarks wdDoc

            currentStep = "writing required values for Excel row " & _
                rowNumber
            WriteRequiredBookmark wdDoc, "ClientName", clientName
            WriteRequiredBookmark wdDoc, _
                "ContractDate", contractDateText

            currentStep = "applying optional sections for Excel row " & _
                rowNumber
            ApplyOptionalBlock wdDoc, "WarrantyBlock", _
                "WarrantyText", includeWarranty, warrantyText
            ApplyOptionalBlock wdDoc, "AppendixBlock", _
                "AppendixText", includeAppendix, appendixText

            currentStep = "saving temporary DOCX for Excel row " & _
                rowNumber
            wdDoc.SaveAs2 tempDocxPath, wdFormatXMLDocument

            currentStep = "exporting temporary PDF for Excel row " & _
                rowNumber
            wdDoc.ExportAsFixedFormat tempPdfPath, wdExportFormatPDF

            wdDoc.Close False
            Set wdDoc = Nothing

            currentStep = "rechecking final output names for Excel row " & _
                rowNumber
            If Len(Dir$(docxPath, FILE_ATTRIBUTES)) > 0 Or _
               Len(Dir$(pdfPath, FILE_ATTRIBUTES)) > 0 Then
                Err.Raise vbObjectError + 2606, , _
                    "A final output appeared after preflight for Excel row " & _
                    rowNumber & ": " & baseName
            End If

            currentStep = "moving the completed pair for Excel row " & _
                rowNumber
            Name tempDocxPath As docxPath
            Name tempPdfPath As pdfPath
            tempDocxPath = vbNullString
            tempPdfPath = vbNullString
            generatedCount = generatedCount + 1
        End If
    Next dataRow

    wdApp.Quit
    Set wdApp = Nothing

    currentStep = "removing the empty run-specific temporary folder"
    RmDir runFolder
    runFolder = vbNullString

    MsgBox generatedCount & _
        " conditional DOCX and PDF pairs were generated.", _
        vbInformation
    Exit Sub

CleanFail:
    errorNumber = Err.Number
    errorDescription = Err.Description

    On Error Resume Next
    If Not wdDoc Is Nothing Then wdDoc.Close False
    If Not wdApp Is Nothing Then wdApp.Quit
    CleanupRunFolder runFolder
    On Error GoTo 0

    MsgBox "Generation stopped while " & currentStep & "." & _
        vbCrLf & "Error " & errorNumber & ": " & _
        errorDescription, vbCritical
End Sub

Private Function CreateRunFolder(ByVal outputFolder As String) As String
    Dim candidateFolder As String
    Dim timeSuffix As String

    timeSuffix = Format$(CLng((Timer - Fix(Timer)) * 1000), "000")
    candidateFolder = JoinPath( _
        outputFolder, _
        "_run_" & Format$(Now, "yyyymmdd_hhnnss") & _
        "_" & timeSuffix)

    If Len(Dir$(candidateFolder, FOLDER_ATTRIBUTES)) > 0 Then
        Err.Raise vbObjectError + 2607, , _
            "A temporary run folder already exists: " & candidateFolder
    End If

    MkDir candidateFolder
    CreateRunFolder = candidateFolder
End Function

Private Sub CleanupRunFolder(ByVal runFolder As String)
    Dim fileSystem As Object

    If Len(runFolder) = 0 Then Exit Sub
    Set fileSystem = CreateObject("Scripting.FileSystemObject")
    If fileSystem.FolderExists(runFolder) Then
        fileSystem.DeleteFolder runFolder, True
    End If
End Sub

Private Sub ValidateHeaders(ByVal ws As Worksheet)
    Dim expectedHeaders As Variant
    Dim columnIndex As Long
    Dim actualHeader As String

    expectedHeaders = Array( _
        "DocumentID", "ClientName", "ContractDateDisplay", _
        "IncludeWarranty", "WarrantyText", _
        "IncludeAppendix", "AppendixText", "Status")

    For columnIndex = 1 To 8
        If IsError(ws.Cells(1, columnIndex).Value) Then
            RaiseCellError ws, ws.Cells(1, columnIndex).Address(False, False), _
                "The header contains an Excel error."
        End If
        actualHeader = Trim$( _
            CStr(ws.Cells(1, columnIndex).Value2))
        If StrComp(actualHeader, _
                   CStr(expectedHeaders(columnIndex - 1)), _
                   vbBinaryCompare) <> 0 Then
            RaiseCellError ws, _
                ws.Cells(1, columnIndex).Address(False, False), _
                "Expected header: " & _
                CStr(expectedHeaders(columnIndex - 1))
        End If
    Next columnIndex
End Sub

Private Sub VerifyTemplateBookmarks(ByVal doc As Object)
    Dim requiredBookmarks As Variant
    Dim bookmarkName As Variant

    requiredBookmarks = Array( _
        "ClientName", "ContractDate", _
        "WarrantyBlock", "WarrantyText", _
        "AppendixBlock", "AppendixText")

    For Each bookmarkName In requiredBookmarks
        If Not doc.Bookmarks.Exists(CStr(bookmarkName)) Then
            Err.Raise vbObjectError + 2610, , _
                "Required Word bookmark is missing: " & _
                CStr(bookmarkName)
        End If
    Next bookmarkName
End Sub

Private Sub WriteRequiredBookmark(ByVal doc As Object, _
                                  ByVal bookmarkName As String, _
                                  ByVal replacementText As String)
    Dim targetRange As Object
    Dim targetStyle As Variant
    Dim wordText As String

    If Not doc.Bookmarks.Exists(bookmarkName) Then
        Err.Raise vbObjectError + 2611, , _
            "Required Word bookmark is missing: " & bookmarkName
    End If

    Set targetRange = doc.Bookmarks(bookmarkName).Range
    targetStyle = targetRange.Style
    wordText = Replace$(replacementText, vbCrLf, vbCr)
    wordText = Replace$(wordText, vbLf, vbCr)
    targetRange.Text = wordText
    targetRange.Style = targetStyle
    doc.Bookmarks.Add bookmarkName, targetRange

    If Not doc.Bookmarks.Exists(bookmarkName) Then
        Err.Raise vbObjectError + 2612, , _
            "Bookmark was not restored: " & bookmarkName
    End If
    If Len(Trim$(doc.Bookmarks(bookmarkName).Range.Text)) = 0 Then
        Err.Raise vbObjectError + 2613, , _
            "Required bookmark is empty after replacement: " & _
            bookmarkName
    End If
End Sub

Private Sub ApplyOptionalBlock(ByVal doc As Object, _
                               ByVal blockBookmark As String, _
                               ByVal textBookmark As String, _
                               ByVal includeBlock As Boolean, _
                               ByVal replacementText As String)
    Dim blockRange As Object

    If includeBlock Then
        WriteRequiredBookmark doc, textBookmark, replacementText
    Else
        Set blockRange = doc.Bookmarks(blockBookmark).Range
        blockRange.Delete
    End If
End Sub

Private Function ReadRequiredText(ByVal sourceValue As Variant, _
                                  ByVal fieldName As String, _
                                  ByVal cellAddress As String) As String
    If IsError(sourceValue) Then
        Err.Raise vbObjectError + 2620, , _
            cellAddress & ": " & fieldName & _
            " contains an Excel error."
    End If

    ReadRequiredText = Trim$(CStr(sourceValue))
    If Len(ReadRequiredText) = 0 Then
        Err.Raise vbObjectError + 2621, , _
            cellAddress & ": " & fieldName & " is required."
    End If
End Function

Private Function ReadOptionalText(ByVal sourceValue As Variant, _
                                  ByVal cellAddress As String) As String
    If IsError(sourceValue) Then
        Err.Raise vbObjectError + 2622, , _
            cellAddress & " contains an Excel error."
    End If
    ReadOptionalText = Trim$(CStr(sourceValue))
End Function

Private Function ReadYesNo(ByVal sourceValue As Variant, _
                           ByVal cellAddress As String) As Boolean
    Dim normalizedValue As String

    normalizedValue = UCase$( _
        ReadOptionalText(sourceValue, cellAddress))
    Select Case normalizedValue
        Case "YES"
            ReadYesNo = True
        Case "NO"
            ReadYesNo = False
        Case Else
            Err.Raise vbObjectError + 2623, , _
                cellAddress & _
                " must contain exactly YES or NO."
    End Select
End Function

Private Function CleanFileName(ByVal rawName As String) As String
    Dim invalidCharacters As Variant
    Dim characterItem As Variant
    Dim characterCode As Long
    Dim cleanedName As String

    cleanedName = Trim$(rawName)
    invalidCharacters = Array( _
        "\", "/", ":", "*", "?", Chr$(34), "<", ">", "|")
    For Each characterItem In invalidCharacters
        cleanedName = Replace$( _
            cleanedName, CStr(characterItem), "_")
    Next characterItem
    For characterCode = 1 To 31
        cleanedName = Replace$( _
            cleanedName, Chr$(characterCode), "_")
    Next characterCode

    Do While Len(cleanedName) > 0
        If Right$(cleanedName, 1) = "." Or _
           Right$(cleanedName, 1) = " " Then
            cleanedName = Left$(cleanedName, Len(cleanedName) - 1)
        Else
            Exit Do
        End If
    Loop

    If Len(cleanedName) = 0 Then
        Err.Raise vbObjectError + 2624, , _
            "DocumentID cannot produce a valid file name."
    End If
    If Len(cleanedName) > 100 Then
        cleanedName = Left$(cleanedName, 100)
    End If
    CleanFileName = cleanedName
End Function

Private Function JoinPath(ByVal folderPath As String, _
                          ByVal childName As String) As String
    If Right$(folderPath, 1) = Application.PathSeparator Then
        JoinPath = folderPath & childName
    Else
        JoinPath = folderPath & Application.PathSeparator & childName
    End If
End Function

Private Sub RaiseCellError(ByVal ws As Worksheet, _
                           ByVal cellAddress As String, _
                           ByVal reason As String)
    Err.Raise vbObjectError + 2625, , _
        ws.Name & "!" & cellAddress & ": " & reason
End Sub
Why the bookmarks are checked first

Word's Bookmarks.Exists method confirms that every required marker is present before values are written or sections are deleted.

What is saved

The macro uses Word SaveAs2 for DOCX and ExportAsFixedFormat for PDF.

What the VBA example protects

The code is intentionally stricter than the original shortcut because conditional output is hard to review after a large batch has already been saved.

Snapshot input

A–H are read into memory once, so one run uses one consistent set of source values.

Preflight before Word

Headers, READY rows, required text, YES/NO flags, duplicate names, and existing files are checked before Word opens.

Fresh template per row

Every document starts from the same untouched template instead of inheriting changes from the prior record.

No ordinary overwrite

The run stops if either the target DOCX or PDF already exists. A shared folder still needs coordination against simultaneous writers.

Whole-block removal

A NO flag deletes the outer bookmarked range. Correct paragraph-mark placement prevents the common empty-line artifact.

Run-scoped cleanup

DOCX and PDF are created inside a unique temporary folder. An error removes only that folder. Files already moved to the final folder are left for manual review rather than deleted automatically.

Formatting boundary

The helper reapplies the uniform style of a text bookmark. It does not reconstruct mixed inline formatting from plain Excel text. Keep complex formatting and fixed boilerplate in Word, then delete or retain the preformatted block as a unit. Test tables, images, headers, and multi-section layouts separately in Word Desktop.

Where DocxForge Pro fits—and where it does not

Use the product when the production model matches one of its two modules. DocxForge Pro is not a general rules engine that evaluates arbitrary Boolean expressions inside any Word template.

Factory: many rows

Factory takes many Excel rows through one standard Word template and creates a separate document for each selected row.

Factory conditional fit

It fits when the optional wording is already resolved into document-ready Excel values and the standard template structure stays the same.

Contractor: one case

Contractor keeps one case's data together and produces several different documents from different Word templates.

Contractor conditional fit

It fits when the decision is which separate documents or templates belong in one case, rather than which rows belong in a mass batch.

When the VBA route remains necessary

If one DOCX must evaluate several rules and physically remove differently formatted regions, keep that logic in tested Word fields, VBA, or another documented assembly layer. Do not assume that ordinary tag replacement automatically removes arbitrary layout blocks.

See both workflows before choosing

The screenshots are grouped by module so the one-case and many-row workflows are not mixed.

Contractor: one case, several different documents

DocxForge Pro Contractor case data screen
Keep the data for one case together.
DocxForge Pro Contractor documents screen
Use different Word templates for the documents in that case.

Factory: many rows, one standard template

DocxForge Pro Factory Excel data screen
Review the source rows used for batch generation.
DocxForge Pro Factory documents screen
Create one standardized output per selected row.
DocxForge Pro pricing

7 days free, then $38 every 3 months • 14-day refund after purchase • Microsoft Word Desktop required • local processing.

Run a six-record pilot before replacing the workflow

Use records that exercise the rules and the layout, not six easy rows with the same flags.

Both blocks included

Confirm headings, body text, styles, and PDF pagination with the longest valid wording.

Both blocks excluded

Confirm there are no empty paragraphs, blank pages, orphan headings, or unexpected table gaps.

Warranty only

Confirm the appendix deletion does not remove neighboring content or change numbering.

Appendix only

Confirm the warranty deletion leaves the appendix at the intended position and spacing.

Bad input

Use one invalid flag or missing required text in a disposable copy and confirm preflight stops before Word opens.

Name collision

Use duplicate IDs in a disposable copy and confirm the batch stops without overwriting an existing result.

Pilot exit criteria

Approve the workflow only after a reviewer checks every flag combination in both DOCX and PDF, verifies the source row against the output, and confirms that the chosen module or macro matches the actual production pattern.

Frequently asked questions

Can Word mail merge use conditional logic?

Yes. Word includes an If...Then...Else rule and other mail merge rules. They work well for short, readable conditions. The workflow becomes fragile when a rule must control a complete formatted region rather than a short text alternative.

Why does a blank line remain after optional text is hidden?

The conditional field or bookmark usually covers the text but not the paragraph mark. For complete removal, the optional range must include the paragraph structure and must be tested beside tables, page breaks, and numbered lists.

Should optional wording live in Excel or Word?

Keep fixed boilerplate and complex formatting in Word. Put record-specific, document-ready values and clear YES/NO decisions in Excel. Do not bury changing business rules in unreadable nested field codes.

What does the VBA example delete?

For a NO flag, it deletes the range marked by WarrantyBlock or AppendixBlock. The template author must include the complete optional block and its final paragraph mark inside that outer bookmark.

Which DocxForge Pro module fits conditional documents?

Factory fits many Excel rows and one standard template. Contractor fits one case and several different documents from different templates. Neither module should be described as a universal Boolean rules engine for arbitrary Word regions.

Will the macro overwrite existing documents?

It blocks existing DOCX or PDF names during an ordinary sequential run and rejects duplicate cleaned names before Word starts. A shared output folder still needs coordination if another process can create the same file at the same time.

Choose the workflow after testing the condition

Keep Word IF rules when they stay simple. Use the VBA pattern when complete blocks must be controlled locally. Choose DocxForge Pro when your process matches Contractor or Factory and you want a repeatable local Excel-to-Word/PDF workflow.

7 days free, then $38 every 3 months • 14-day refund after purchase • Microsoft Word Desktop required • local processing.