0

在将大量(150 个?)标注(边缘中的简单文本框,没有边框)添加到带有镜像奇数/偶数页的 Word 2010 .docx 文件后,我需要调整一些文本。这将文档缩短到足以删除一页,因此调整后的所有奇数页都变成了偶数页,而偶数页变成了奇数页。文本框没有移动,现在它们都从纸张边缘掉了下来,由于纸张边界之外的文本没有显示在文档中,甚至都很难找到它们,更不用说移动它们了到他们在相反边距的正确位置。此外,我可能需要再次调整文本,问题可能会再次出现。

我正在寻找一种自动化的方式,使用 VBA(我绝对是一个新手,虽然是一个专家程序员),记录一些宏来说,“将所有现有的文本框居中在宽边距中,并使宽度一致。” 就像是,

作为一个文本框,如果我发现自己在奇数页上,使文本框的左边缘距页面左边缘 0.5";如果我在偶数页上,使文本框的左边缘在右边距 + 0.5"。我的身高应该是一致的,我的身高可以保持原来的样子。

我需要知道用什么单位来表示 Top 和 Width 值,如何确定我是在奇数/偶数页上,以及如何找到所有文本框。

任何人都可以帮忙吗?

4

1 回答 1

1
Sub AdjustTextBoxes()

Dim myTextBox As Shape
Dim PageNumber As Integer

For Each myTextBox In ActiveDocument.Shapes
    If myTextBox.Type = msoTextBox Then
        myTextBox.Select
        PageNumber = Selection.Information(wdActiveEndPageNumber)
        'Mod returns the remainder (rounded up) of the division.
        'No remainder is even. Any remainder is an odd page.
        If PageNumber Mod 2 = 1 Then
            With myTextBox 'Odd numbered pages
                .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage 
                .Left = InchesToPoints(0.5)
            End With
        Else
            'Because wdRelativeHorizontalPositonPage measures from the left
            'edge of the page the positioning for text boxes on even pages
            'is not based on the distance from the right margin.
            'So below .Left = 8.5" (page width) - (1" (textbox with) + .5" (distance
            'from the right edge of the page). The measurement for .left below
            'will need to be altered based on the position from the right edge
            'of the page and the width of your text boxes and pages.
            With myTextBox 'Even numbered pages
                .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
                .Left = InchesToPoints(7)
            End With
        End If
    End If
Next

End Sub
于 2013-01-27T06:39:04.403 回答