遍历Word中的页面并查找包含图像的页面 [英] Iterate through pages in Word and find pages contains image
问题描述
我想遍历word文档中的每个页面,检查该页面是否包含图像,然后对该页面进行一些操作(设置页面边距并插入一个分隔符).
I want to iterate though every page in a word document, check if that page contains an images or not, and do something about that page (Set page margin and insert a break).
For Each Page in Document.Pages
If Page.ContainsImage Then
Page.TopMargin = 0
DoOtherStuff
End If
Next
推荐答案
Document
具有表示所有Shape的Shapes
集合.每个Shape都有一个Anchor
,通过它可以访问该形状页面的TopMargin
和其他属性:
A Document
has a Shapes
Collection representing all the Shapes. Each Shape has an Anchor
, using which we can get to the TopMargin
, and other properties, of the shape's page:
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)
有一个Pages
集合,但是它不像IMO有用:
There is a Pages
Collection but it is not as useful 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
是否是图像.
With this approach you would have to delve into the Rectangles
collection and use RectangleType
to try to determine if the current Rectangle
is an image.
这篇关于遍历Word中的页面并查找包含图像的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!