Skip to content

Integration: Word

DVDAddin talks to Microsoft Word over COM: generating documents in bulk from an Excel table, and batch-converting Word files to PDF. This page spells out the add-in's actual mail-merge mechanism, what it does not do, and how to work around those limits.

CommandRibbon locationWhat it does
Create TitleDVD Addin › File and Print › Merge MenuWraps the table's header row into [Column name] — preparation for the merge
Merge to WordDVD Addin › File and PrintEach data row → one Word file from the selected template(s)
Word → PDFDVD Addin › File and Print › PDF / OCR MenuPick several .doc/.docx files → export PDFs with the same name, in the same folder

Placeholder syntax: [ColumnName]

This is what people get wrong most often. DVDAddin does not use {{...}}, does not use Word's Merge Fields, and has no format modifiers such as |VND or |dd/MM/yyyy. There is only one rule:

The string [Column name] in the Word template is replaced with the cell value of the column with the same name on the row being processed.

The name inside the square brackets must match the column header exactly — including Vietnamese diacritics and spacing. Hence the standard procedure:

  1. On the sheet, prepare the table with a header row.
  2. Run Create Title and select exactly the header row → Số phiếu ("Form no.") becomes [Số phiếu].
  3. Copy those strings and paste them straight into the Word template — no typing by hand, no spelling mistakes.

WARNING

The Create Title command overwrites cell values, cannot be undone with Ctrl+Z, and running it twice produces [[Số phiếu]]. Save a copy before running it.

Use cases

1. Batch Word merge

→ See Merge to Word.

You specify: the folder holding the templates, the folder for the results, the templates to use (several can be selected), the data range including its header, and the column used for the output file name. Each row × each template = one .docx file.

Picking 3 templates and 35 data rows means 105 files — the count multiplies, it does not add up. Check before you click.

2. Batch-convert Word to PDF

→ See Word → PDF.

The file picker filters on *.doc; *.docx — select with Ctrl/Shift/Ctrl+A. The add-in opens Word hidden, opens each file read-only, exports a PDF with the same name, in the same folder as the original, then closes Word. Files that fail are skipped, and it finishes with a message of the form "Converted 18/20 Word files to PDF."

The PDF follows the page setup of the Word document itself (paper size, margins, header/footer) — if you want a different PDF, change it in Word first.

3. Getting a table from Word into Excel

The add-in has no command that reads tables directly from .docx. Two workarounds, both using real commands:

Route A — via PDF (recommended):

  1. Word → PDF the Word file you need to extract from.
  2. Extract Table — the AI recognises the table in the PDF, preserving rows/columns and merged cells (rowspan/colspan), with a preview window for editing individual cells before pasting.

Route B — no network needed: Word → Save AsWeb Page (.htm) → open the HTML file with Excel; Excel turns the table into cells. Fast and free, but the formatting is messier and merged cells usually break.

4. Conditional content in the document

There is no [CONDITIONAL: ...] syntax in Word templates. The real approach is to push the condition up into Excel: add a column, name it exactly as the placeholder, and have it return an empty string when the clause is not needed.

For example, with the header column [Điều khoản bảo lãnh] ("Guarantee clause"):

=IF(GiaTri > 1000000000; "Điều 8. Bảo lãnh thực hiện hợp đồng: ..."; "")

In the Word template, put [Điều khoản bảo lãnh] in its own paragraph. When the value exceeds 1 billion the paragraph has content; otherwise the paragraph is empty — a blank line still remains, which you either delete by hand or accept.

To spell an amount out in words in the document, use a helper column with dvdVnd (or dvdUsd) and then merge that column:

=dvdVnd(F12; 1)

The second argument is match_mode: 0 (the default) returns the bare words, 1 adds the prefix Bằng chữ: .

Preparing the Word template

The add-in ships no Word template

The C:\DVDAddin\Template\ folder holds only 6 Excel files:

FileCommand that opens it
FormNTCV.xlsxWork Record Tpl — work acceptance record
FormNTVL.xlsxMaterial Record Tpl — material acceptance
FormNKCT.xlsxDiary Template — construction diary
SendEmail.xlsxEmail Template
GanttChart.xlsxGantt Tpl
RebarCutOptimizer.xlsxCutting Tpl

The Word templates for the Merge command are yours to prepare. That is in fact a strength: you use exactly the form the project's employer / supervision consultant requires, instead of adapting somebody else's template.

Designing your own template

  1. Open Word → create a new document, set up the logo, header, footer and styles.
  2. Paste the [Column name] strings exactly where the values belong.
  3. Save the .docx into a dedicated folder that holds templates only (the Merge dialog lists every file in that folder).
  4. Test with 2–3 data rows before issuing the whole batch.

Three traps when placing placeholders

  • Word fragments the string. If you type [Hạng mục] ("Work item") and then edit letters in the middle, Word may split it into several different "runs"; find/replace then cannot match the whole string. The safe way: delete the placeholder completely and paste it back in one go from Excel.
  • Headers, footers, text boxes. A placeholder outside the document body may not be replaced. Put the important fields in the body; if one really has to sit in the header, check the first output file.
  • Character formatting. If you bold only part of [Hạng mục], the replaced result may lose the formatting. Bold the whole string, both brackets included.

Sharing templates across the team

Put the template folder on OneDrive / SharePoint / a network drive and point the Merge dialog at it. The whole team uses one set of templates; edit once and everyone has the new version. Name the template files by record type (BBNT_CongViec.docx, PhieuYCNT.docx) so the selection list is easy to read.

Word's own mail merge versus DVDAddin

CriterionWord's Mail MergeDVDAddin's Merge to Word
Data sourceExcel / CSV / Access / contactsOne Excel range with a header
Merge fieldMerge Field (Ctrl+F9)The text string [Column name]
ResultOne long document, or print / send by mailMany separate .docx files, one per row
Naming each fileRequires a macroPick a column as the file name
Several templates at onceNoYes — tick several templates, each row yields the full set
Conditional contentIF fields, hard to writeExcel formulas in the source column
PDF exportBuilt inA separate step with Word → PDF

The practical conclusion: when you need a set of separate files named by record code, use DVDAddin; when you need one long document or a direct mail-merge send, Word's own feature is still more convenient.

Converting old .doc to .docx

The add-in has no dedicated command for this, but Word → PDF accepts .doc as well — if PDF is the final destination, no intermediate conversion is needed.

When you genuinely need .docx (to serve as a merge template, for instance), this script works as is:

python
import win32com.client, glob

word = win32com.client.Dispatch('Word.Application')
word.Visible = False

for path in glob.glob(r'D:\OldDocs\*.doc'):
    doc = word.Documents.Open(path)
    doc.SaveAs(path + 'x', FileFormat=16)   # 16 = wdFormatXMLDocument
    doc.Close()
    print('Converted:', path)

word.Quit()

Troubleshooting

#1 — "Microsoft Word is not installed."

The Word.Application ProgID is not registered — the machine only has Excel installed, or the Office installation is damaged. Install Word, or run a Repair on the Office suite.

#2 — A WINWORD.EXE process left hanging

If the command is interrupted halfway, the hidden Word session can survive and hold memory. Clean it up in Task Manager, or:

powershell
Get-Process WINWORD -ErrorAction SilentlyContinue | Stop-Process -Force

Check that none of your own Word documents are open before running this — it closes them all, without asking.

#3 — "Document is locked for editing"

The template file or the output file is open in another Word window, or a leftover ~$name.docx file is still there. Close every Word and run again; if it still fails, delete the ~$*.docx files in the template folder.

#4 — Placeholder not replaced

Check in this order:

  1. Does the name inside [...] match the column header absolutely exactly (diacritics, upper/lower case, stray spaces)?
  2. Does the selected data range include the header row?
  3. Is the placeholder inside a header/footer/text box?
  4. Has Word fragmented it — try deleting it and pasting the whole string back.

#5 — Fonts substituted in the PDF

Word exports the PDF using the fonts present on the machine. A font used by the template but missing from the machine is substituted and the layout breaks. Install every font the template uses, or embed the fonts: Word → File → Options → Save → Embed fonts in the file.

#6 — Output files overwritten and lost

If the column chosen as the file name has two rows with the same value, the later file overwrites the earlier one, without asking and with no undo. Choose a column with unique values (form number, element code), or add a helper column joining the code with a sequence number using dvdTextJoin.

Released under DVDAddin License.