[英]Convert all shape to image in Ms word with macro
我寫這個宏來將文檔中的所有形狀轉換為圖像:
Sub AllShapeToPic()
For Each oShp In ActiveDocument.Shapes
oShp.Select
Selection.Cut
Selection.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, DisplayAsIcon:=False
Next oShp
End Sub
但是當我運行它時,沒有任何形狀轉換為圖像。
我的宏代碼有什么問題?
歡迎來到操縱您正在循環的集合的精彩世界。 你切割的那一刻,你正在有效地從集合中移除形狀,改變你的循環。
如果您想循環遍歷形狀(或表格行或其他)並從該集合中刪除某些內容,只需向后退:
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
或者表格(警告:未經測試!)
Dim tbl As Table
For i = ActiveDocument.Tables.Count To 1 Step -1
Set tbl = ActiveDocument.Tables(i)
tbl.Select
Selection.Cut
Selection.PasteSpecial Link:=False, dataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, DisplayAsIcon:=False
Next i
對於方程:方程是InlineShapes並具有“OMath”屬性。 用它來識別方程對象。 警告:未經測試
Dim equation As InlineShape
For i = ActiveDocument.InlineShapes.Count To 1 Step -1
Set equation = ActiveDocument.InlineShapes(i)
If equation.OMath > 0 Then
equation.Select
Selection.Cut
Selection.PasteSpecial Link:=False, dataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, DisplayAsIcon:=False
End If
Next i
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.