作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有一些图像的 2010 Word 文档。我已经一张一张地导出了图像。由于文档目标的格式,我需要删除所有图像并在图像曾经存在的地方留下一个文本 block (类似于 [[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
最佳答案
两种适用于InlineShapes
的可能解决方案仅(根据可能没问题的评论。)
解决方案一不断替换文本:
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
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
关于image - 用字符串/文本占位符替换 Word 文档中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17033374/
我是一名优秀的程序员,十分优秀!