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

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

以下VBA宏将在Word 2000(或更高版本)中工作,以创建一个以点和像素为单位显示文档中所有图形对象大小的文档:

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 97中不起作用,因为Word 97无法识别PointsToPixels语句。如果删除使用此语句的行(或创建自己的PointsToPixels函数),则该宏将在Word 97下正常工作。

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

注意:

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

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

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

(Microsoft Word是世界上最流行的文字处理软件。)本技巧(1497)适用于Microsoft Word 97、2000、2002和2003。您可以为Word(Word 2007)的功能区界面找到此技巧的版本。和更高版本)在这里:

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