我有这个宏将文档中的所有形状转换为图像:
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
答案 0 :(得分:6)
您正在遍历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
答案 1 :(得分:2)