replace each MS Word file equation with an image while preserving original/equation size and position

JohnQPublic 0 Reputation points
2026-11-21T17:06:15.0866667+00:00

I interact with MS Word files that have standalone equations, equations in table cells, and equations embedded within paragraphs. Is there a VBA macro way and/or other way [e.g., third party tool] to replace each equation with an image while preserving the original/equation size and position?

Microsoft 365 and Office | Word | For business | Windows
0 comments No comments

Answer accepted by question author
Hani-Ng 2,935 Reputation points Independent Advisor
2026-11-21T17:36:27.9733333+00:00

Hi JohnQPublic

You can refer to AI's VBA method first which is a reasonable approach if your equations are native Word equations (Office Math/OMML). Before implementing it widely, I would recommend testing it on a copy of a representative document because equation-to-image replacement can affect line wrapping, row heights in tables, and page breaks, particularly in complex documents.

One point to be aware of is that Word does not provide a built-in feature specifically designed to convert all equations to pictures while guaranteeing pixel-perfect preservation of formatting in every scenario. Documents containing inline equations, display equations, tables, text boxes, headers, footers, or third-party equation objects (such as MathType or legacy Equation Editor objects) may require additional handling.

If your primary goal is document distribution rather than editing, another option is to export the document to PDF, where equations are rendered as graphics for viewing while retaining the visual layout. This can often achieve the desired result without modifying the original Word file.

If you need the equations replaced within the Word document itself, could you clarify:

  • Are the equations native Word equations (inserted via Insert > Equation) or created with MathType/another tool?
  • Are you processing a few documents manually or a large number of documents in an automated workflow?

I hope this information helps and look forward to your response.

Was this answer helpful?

3 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. AI answer

    2026-11-21T17:07:18.98+00:00

    Moderator note:

    This was marked as not helpful by JohnQPublic (the person who asked the question). I have restored it because it is referenced in the response marked as an Answer and may be helpful.

    Use Word VBA to copy each native Office Math equation as a picture and paste it directly over the equation’s range; this preserves its location in paragraphs and table cells and normally preserves its rendered dimensions.

    VBA macro

    Make a backup first: the macro permanently replaces editable equations with pictures.

    1. Save a copy of the document as Word Macro-Enabled Document (.docm).
    2. Press Alt+F11.
    3. Select Insert > Module.
    4. Paste and run this macro:
    Sub ReplaceEquationsWithPictures()
        Dim i As Long
        Dim eqRange As Word.Range
    
        Application.ScreenUpdating = False
        On Error GoTo CleanUp
    
        'Work backward so replacements do not disturb later ranges.
        For i = ActiveDocument.OMaths.Count To 1 Step -1
            Set eqRange = ActiveDocument.OMaths(i).Range.Duplicate
    
            eqRange.CopyAsPicture
            eqRange.PasteSpecial _
                Link:=False, _
                Placement:=wdInLine, _
                DataType:=wdPasteMetafilePicture
        Next i
    
    CleanUp:
        Application.ScreenUpdating = True
    
        If Err.Number <> 0 Then
            MsgBox "Stopped at equation " & i & ":" & vbCrLf & _
                   Err.Description, vbExclamation
        Else
            MsgBox "All Office Math equations were replaced.", vbInformation
        End If
    End Sub
    

    Word exposes native equations through the document’s OMaths collection, with each OMath.Range identifying the equation’s exact text range.^1^ ^2^ The macro duplicates that range so its endpoints can be used safely during replacement.

    CopyAsPicture copies the rendered range as a picture; Microsoft’s example pastes the result using wdPasteMetafilePicture.^3^ Because PasteSpecial is called on the original, non-collapsed equation range, the picture replaces that range rather than being inserted beside it. Placement:=wdInLine makes the result participate in text flow as a character.^4^ Inline pictures are positioned like characters, which is appropriate for equations embedded in paragraphs and table cells.^5^

    Layout expectations and limitations

    • Inline equations: remain at the same character position and retain surrounding paragraph flow.
    • Equations in table cells: remain in the same cell; the table layout may recalculate if Word interprets the pasted picture’s metrics slightly differently.
    • Standalone equations: remain in the same paragraph. Existing paragraph alignment, indentation, spacing, and table-cell alignment remain applicable.
    • Image dimensions: CopyAsPicture normally carries the equation’s rendered dimensions into the metafile. The macro deliberately does not set Width or Height, because an OMath object does not expose those picture-style dimensions directly.
    • Editability: the results are pictures, not equations. Keep the original document if later equation editing may be required.
    • Other document stories: ActiveDocument.OMaths addresses the document equation collection. Equations in headers, footers, or text boxes may require separate processing through StoryRanges; Word represents those document areas as separate stories.^6^

    If some equations are skipped

    The macro targets native Office Math/OMML equations. Select a skipped equation:

    • If Equation Tools appears, it should normally be an Office Math equation.
    • If it is an older Microsoft Equation Editor object, convert it first by double-clicking it or selecting it and pressing Enter, then accept Word’s conversion prompt. That converter is available in Microsoft 365 and Office 2019 build 16.0.10730 or later, and the document may need to be saved as .docx first.^7^
    • Third-party equation objects, such as unconverted MathType/OLE objects, are not members of OMaths and require tool-specific conversion or separate OLE-object handling.

    Run the macro on a representative copy first and compare page count, table row heights, line wrapping, and equation baselines before processing the production files.


    References

    1. Document.OMaths property (Word)
    2. OMath object (Word)
    3. Range.CopyAsPicture method (Word)
    4. Range.PasteSpecial method (Word)
    5. InlineShape object (Word)
    6. Document.StoryRanges property (Word)
    7. [Newer versions](#tab/newer-versions)
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.