使用宏将Word文档中的公式转换为图像 [英] Convert formula in a word document to image with macro

查看:21
本文介绍了使用宏将Word文档中的公式转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此宏将文档中的所有形状转换为图像:

Dim i As Integer, oShp As Shape

For i = ActiveDocument.Shapes.Count To 1 Step -1
    Set oShp = ActiveDocument.Shapes(i)
    oShp.Select
    Selection.Cut
    Selection.PasteSpecial Link:=False, dataType:=wdPasteEnhancedMetafile, _
        Placement:=wdInLine, DisplayAsIcon:=False
Next i

但我想将所有数学公式转换为图像。如何更改此宏才能执行此操作?

更新:
我尝试了此代码,但不起作用:(没有错误,也没有结果)

Sub AllEquationToPic()
Dim z As Integer, equation As OMath

For z = ActiveDocument.InlineShapes.Count To 1 Step -1
    Set equation = ActiveDocument.OMaths(z)
        equation.Range.Select
        Selection.Cut
        Selection.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
            Placement:=wdInLine, DisplayAsIcon:=False
Next z
End Sub

推荐答案

您正在迭代InlineShapes集合,但使用z访问OMaths集合。那是胡说八道。 然后尝试此操作:

Sub AllEquationToPic()
Dim z As Integer, equation As OMath

For z = ActiveDocument.OMaths.Count To 1 Step -1
    Set equation = ActiveDocument.OMaths(z)
        equation.Range.Select
        Selection.Cut
        Selection.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
            Placement:=wdInLine, DisplayAsIcon:=False
Next z
End Sub

编辑:这里有一个使用内联公式效果更好的替代方案,尽管产生的图像质量略差:

Sub FormulaDoc2PicDoc()
Dim doc As Document, docPath As String, htmPath As String
Dim alertStatus

alertStatus = Application.DisplayAlerts
Application.DisplayAlerts = wdAlertsNone

Set doc = ActiveDocument
docPath = doc.FullName
htmPath = docPath & ".htm"

doc.SaveAs htmPath, wdFormatFilteredHTML
doc.Close False

Application.DisplayAlerts = alertStatus

Set doc = Documents.Open(htmPath, False)

End Sub

这篇关于使用宏将Word文档中的公式转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆