我想写一个宏,它可以将word文档中的所有形状和图片转换为内联文本。我使用的代码将所有形状(由绘图工具编辑)转换为内联文本,但先前转换为图片(由图片工具编辑)或任何其他图片的表格不是将其包装为内联文本的文本。粘贴我正在使用的代码
For Each oShp In ActiveDocument.Shapes
oShp.Select
Selection.ShapeRange.WrapFormat.Type = wdWrapInline
Next oShp发布于 2014-08-04 23:29:44
第一个答案是一个良好的开始,但有一个问题。For Each遍历集合,但集合被ConvertToInlineShape更改。在其他语言中,这会抛出一个异常,即集合已被修改,在这里它只是静默地停止。
为了避免这种情况,您需要将每个形状添加到另一个集合中,并在那里迭代它们。或者,对于下面的示例,只需手动跟踪索引即可。
Sub InlineAllImages()
Dim Shape As Shape
Dim Index As Integer: Index = 1
' Store the count as it will change each time.
Dim NumberOfShapes As Integer: NumberOfShapes = Shapes.Count
' Break out if either all shapes have been checked or there are none left.
Do While Shapes.Count > 0 And Index < NumberOfShapes + 1
With Shapes(Index)
If .Type = msoPicture Then
' If the shape is a picture convert it to inline.
' It will be removed from the collection so don't increment the Index.
.ConvertToInlineShape
Else
' The shape is not a picture so increment the index (move to next shape).
Index = Index + 1
End If
End With
Loop
End Sub发布于 2013-08-22 06:16:44
试一试
For Each oShp In ActiveDocument.Shapes
oShp.Select
Selection.ShapeRange.ConvertToInlineShape
Next oShp发布于 2018-06-06 08:03:40
我认为选择每个迭代形状是不必要的,而且可能会成为障碍。
任何还需要答案的人,这对我都很有效:
For Count = 1 To 2
For Each oShp In ActiveDocument.Shapes
oShp.ConvertToInlineShape
Next oShp
Next Count外部循环的第一次迭代处理图片,第二次迭代处理绘图对象。不要问为什么!
https://stackoverflow.com/questions/15919815
复制相似问题