使用项目的单词 VBA 个形状
Word VBA Shapes Using Item
我有以下代码:
Sub removeTopAndBottomMostShapesFromActiveDocument()
Dim shape As shape
Dim topShape As shape
Dim bottomShape As shape
Dim pageNum
For pageNum = 1 To ActiveWindow.Panes(1).Pages.Count
Dim highestPoint, lowestPoint
highestPoint = 999999
lowestPoint = -999999
Set topShape = Nothing
Set bottomShape = Nothing
Dim sr As ShapeRange
Set sr = ActiveWindow.Panes(1).Pages(pageNum).Rectangles.Item(1).Range.ShapeRange
sr.Select
For Each shape In sr
If shape.Top < highestPoint Then
Set topShape = shape
highestPoint = shape.Top
End If
If shape.Top + shape.Height > lowestPoint Then
Set bottomShape = shape
lowestPoint = shape.Top + shape.Height
End If
Next
If Not topShape Is Nothing Then
topShape.Delete
End If
If Not bottomShape Is Nothing Then
bottomShape.Delete
End If
使用 Set sr = Activewindow
...我无法弄清楚 .item(1)
的作用。我的 Word 文档中的文本框都是一样的。在某些页面上,.item(1)
会给出“0”的 sr.count
,但如果我更改为 .item(2)
或 .item(3)
,则会在特定页面上找到文本框。任何帮助将不胜感激。
在此处阅读第 2 项:
我们最近对 Word 做了很多工作,它的行为正如文章所说,Word 和 Pages 不能很好地结合在一起。
.Items(1) 应该提供该页面上的所有矩形,但我怀疑它对页面感到困惑(请记住,每次删除一个形状时,整个文档都会移动,而一个形状上的形状页面现在将在另一个页面上)。
我也会质疑你正在尝试做的事情的有效性。如果一个人的分辨率比另一个人高得多,那么在一个人的机器上位于页面顶部和底部的形状可能在另一个人的机器上不存在。
我想我找到了解决方法。由于某种原因,文本框被放置在不同的项目中,即使它们是由完全相同的过程创建的。如果有人可以解释这一点,我将不胜感激。所以解决方案是用 .Item(i) 从 1 到 3 创建一个循环,它抓取页面上的所有框并且似乎可以正常工作。
我有以下代码:
Sub removeTopAndBottomMostShapesFromActiveDocument()
Dim shape As shape
Dim topShape As shape
Dim bottomShape As shape
Dim pageNum
For pageNum = 1 To ActiveWindow.Panes(1).Pages.Count
Dim highestPoint, lowestPoint
highestPoint = 999999
lowestPoint = -999999
Set topShape = Nothing
Set bottomShape = Nothing
Dim sr As ShapeRange
Set sr = ActiveWindow.Panes(1).Pages(pageNum).Rectangles.Item(1).Range.ShapeRange
sr.Select
For Each shape In sr
If shape.Top < highestPoint Then
Set topShape = shape
highestPoint = shape.Top
End If
If shape.Top + shape.Height > lowestPoint Then
Set bottomShape = shape
lowestPoint = shape.Top + shape.Height
End If
Next
If Not topShape Is Nothing Then
topShape.Delete
End If
If Not bottomShape Is Nothing Then
bottomShape.Delete
End If
使用 Set sr = Activewindow
...我无法弄清楚 .item(1)
的作用。我的 Word 文档中的文本框都是一样的。在某些页面上,.item(1)
会给出“0”的 sr.count
,但如果我更改为 .item(2)
或 .item(3)
,则会在特定页面上找到文本框。任何帮助将不胜感激。
在此处阅读第 2 项:
我们最近对 Word 做了很多工作,它的行为正如文章所说,Word 和 Pages 不能很好地结合在一起。
.Items(1) 应该提供该页面上的所有矩形,但我怀疑它对页面感到困惑(请记住,每次删除一个形状时,整个文档都会移动,而一个形状上的形状页面现在将在另一个页面上)。
我也会质疑你正在尝试做的事情的有效性。如果一个人的分辨率比另一个人高得多,那么在一个人的机器上位于页面顶部和底部的形状可能在另一个人的机器上不存在。
我想我找到了解决方法。由于某种原因,文本框被放置在不同的项目中,即使它们是由完全相同的过程创建的。如果有人可以解释这一点,我将不胜感激。所以解决方案是用 .Item(i) 从 1 到 3 创建一个循环,它抓取页面上的所有框并且似乎可以正常工作。