我想遍历 word 文档中的每一页,检查该页面是否包含图像,并对该页面执行一些操作(设置页边距并插入中断)。
For Each Page in Document.Pages
If Page.ContainsImage Then
Page.TopMargin = 0
DoOtherStuff
End If
Next
ADocument有一个Shapes代表所有形状的集合。每个 Shape 都有一个Anchor,我们可以使用它来TopMargin访问 shape 页面的 和其他属性:
Sub JiggleAllShapes()
Dim shp As Shape
For Each shp In ActiveDocument.Shapes
shp.Anchor.Paragraphs(1).Range.PageSetup.TopMargin = 0
Next shp
End Sub
我们可以从以下位置获取页码Anchor:
shp.Anchor.Information(wdActiveEndPageNumber)
有一个PagesCollection,但它没有 IMO 有用:
Sub WhatAboutPages()
Dim pge As Page
For Each pge In ActiveDocument.ActiveWindow.Panes(1).Pages
'Debug.Print pge.NothingUsefulHere
Next pge
End Sub
使用这种方法,您必须深入研究Rectangles集合并使用它RectangleType来尝试确定当前Rectangle是否是图像。