Word将有关您插入到文档中的图像的信息保持在一起。此信息是必需的,以便Word知道如何调整大小,位置和显示图像。如果要查找有关文档中图像的更多信息,则需要了解有关Word如何存储信息的一些信息。

图像存储为两种类型的图形对象之一:常规形状或嵌入式形状。规则形状是驻留在绘图层上的形状,而内联形状则驻留在文本层上。两种类型的对象都存储有不同的对象集合。常规形状在Shapes集合中,内嵌形状存储在InlineShapes集合中。要访问有关对象的信息,您只需要使用一些VBA。

下面的VBA宏创建一个文档,该文档以点和像素为单位显示文档中所有图形对象的大小:

Sub FigureInfo()

Dim iShapeCount As Integer     Dim iILShapeCount As Integer     Dim DocThis As Document     Dim J As Integer     Dim sTemp As String

Set DocThis = ActiveDocument     Documents.Add

iShapeCount = DocThis.Shapes.Count     If iShapeCount > 0 Then         Selection.TypeText Text:="Regular Shapes"

Selection.TypeParagraph     End If     For J = 1 To iShapeCount         Selection.TypeText Text:=DocThis.Shapes(J).Name         Selection.TypeParagraph         sTemp = "     Height (points): "

sTemp = sTemp & DocThis.Shapes(J).Height         Selection.TypeText Text:=sTemp         Selection.TypeParagraph         sTemp = "     Width (points): "

sTemp = sTemp & DocThis.Shapes(J).Width         Selection.TypeText Text:=sTemp         Selection.TypeParagraph         sTemp = "     Height (pixels): "

sTemp = sTemp & PointsToPixels(DocThis.Shapes(J).Height, True)

Selection.TypeText Text:=sTemp         Selection.TypeParagraph         sTemp = "     Width (pixels): "

sTemp = sTemp & PointsToPixels(DocThis.Shapes(J).Width, False)

Selection.TypeText Text:=sTemp         Selection.TypeParagraph         Selection.TypeParagraph     Next J

iILShapeCount = DocThis.InlineShapes.Count     If iILShapeCount > 0 Then         Selection.TypeText Text:="Inline Shapes"

Selection.TypeParagraph     End If     For J = 1 To iILShapeCount         Selection.TypeText Text:="Shape " & J         Selection.TypeParagraph         sTemp = "     Height (points): "

sTemp = sTemp & DocThis.InlineShapes(J).Height         Selection.TypeText Text:=sTemp         Selection.TypeParagraph         sTemp = "     Width (points): "

sTemp = sTemp & DocThis.InlineShapes(J).Width         Selection.TypeText Text:=sTemp         Selection.TypeParagraph         sTemp = "     Height (pixels): "

sTemp = sTemp & PointsToPixels(DocThis.InlineShapes(J).Height, True)

Selection.TypeText Text:=sTemp         Selection.TypeParagraph         sTemp = "     Width (pixels): "

sTemp = sTemp & PointsToPixels(DocThis.InlineShapes(J).Width, False)

Selection.TypeText Text:=sTemp         Selection.TypeParagraph         Selection.TypeParagraph     Next J End Sub

请注意,宏返回常规形状的名称,但不返回内联形状的名称。原因是Word不维护内联形状的名称。当您在文档中再次插入常规形状时(同样在图形图层上),Word会为该形状分配名称,例如Rectangle 2或Oval 3。

注意:

如果您想知道如何使用此页面(或_WordTips_网站上的任何其他页面)上描述的宏,我准备了一个包含有用信息的特殊页面。

链接:/ wordribbon-WordTipsMacros [点击此处在新的浏览器标签中打开该特殊页面]。

_WordTips_是您进行经济有效的Microsoft Word培训的来源。

(Microsoft Word是世界上最流行的文字处理软件。)本技巧(8343)适用于Microsoft Word 2007、2010、2013、2016、2019和Office 365中的Word。 Word的旧菜单界面在这里:

链接:/ word-Determining_Picture_Size_in_a_Macro [确定宏中的图片大小]。