I have this macro to convert all shapes in the document to an image :
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
But I want to convert all math formulas to image. How can I change this macro to do this?
UPDATE:
I tried this code but doesnt work : (No error and also no result)
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
You are iterating through the InlineShapes
collection but using z
to access the OMaths
collection. That's nonsense.
Try this then:
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
Edit: Here is an alternative that works better with inline formulae albeit with slightly worse resulting image quality:
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
Try the other values for DataType
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With