gpt4 book ai didi

image - 用字符串/文本占位符替换 Word 文档中的图像

转载 作者:行者123 更新时间:2023-12-02 00:08:14 24 4
gpt4 key购买 nike

我有一个带有一些图像的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com