4

我有一个带有一些图像的 2010 Word 文档。我已经一张一张地导出了图像。由于文档目标的格式,我需要删除所有图像并在图像曾经存在的地方留下一个文本块(类似于 [[Image1.jpg]])。

图像的名称实际上并不重要。我只需要将图像换成文本。我对 Word 中的 VBA 完全陌生。

这是调整图像大小的其他代码,可以修改它以删除图像并在该位置插入一些文本吗?

Dim oShp As Shape
Dim oILShp As InlineShape

For Each oShp In ActiveDocument.Shapes
    With oShp
        .Height = AspectHt(.Width, .Height, _
        CentimetersToPoints(11))
        .Width = CentimetersToPoints(11)
    End With
Next

For Each oILShp In ActiveDocument.InlineShapes
    With oILShp
        .Height = AspectHt(.Width, .Height, _
        CentimetersToPoints(11))
        .Width = CentimetersToPoints(11)
    End With
Next
End Sub
4

1 回答 1

4

两种可能的解决方案InlineShapes只能使用(根据可能没问题的评论。)

解决方案 1常量替换文本:

Sub ReplaceInlineShapes_constant_names()

Dim oILShp As InlineShape

For Each oILShp In ActiveDocument.InlineShapes

    'insert text in place where InlineShape is located
    ActiveDocument.Range(oILShp.Range.Start, oILShp.Range.End).Text = "[Image.Jpg]"
    'delete picture is not needed- it was simply replaced with text

Next
End Sub

解决方案 2替换带有索引的文本:

Sub ReplaceInlineShapes_WithIndex()

Dim oILShp As InlineShape
Dim ILShpIndex As Integer
For Each oILShp In ActiveDocument.InlineShapes
    ILShpIndex = ILShpIndex + 1
    'insert text in place where InlineShape is located
    ActiveDocument.Range(oILShp.Range.Start, oILShp.Range.End).Text = _
                                "[Image" & ILShpIndex & ".Jpg]"
    'delete picture is not needed- it was simply replaced with text

Next
End Sub
于 2013-06-10T22:12:24.143 回答