我必须检查以下的许多Word文档:
边距:left = right = top = bottom =特定值,例如(0.5英寸)
我正在尝试编写一个可以报告上述内容的小型vba脚本。我刚刚开始,目前已经能够找到ActiveDocument.PageSetup
,它为四个边距中的每一个提供了4个属性。我对VBA很新,检查平等对我没有用,这就是我的尝试:
Sub check()
With ActiveDocument.PageSetup
If (.LeftMargin = .RightMargin = .TopMargin = .BottomMargin = 72) Then
MsgBox ("all margins equal to 72 points")
Else
MsgBox ("one or more margins not set to 72 points")
End If
End With
End Sub
我一直收到Else
下的消息。非常感谢所有的帮助。
答案 0 :(得分:0)
不是手动将所有内容转换为点数,而是使用Word' InchesToPoints'功能。例如:
Sub CheckMargins()
Dim StrMrgn As String, sMrgn As Single, StrOut As String
StrMrgn = InputBox("What is the required margin, in inches?", "Margin checker")
If Not IsNumeric(StrMrgn) Then Exit Sub
sMrgn = InchesToPoints(CSng(StrMrgn))
MsgBox sMrgn
With ActiveDocument.PageSetup
If (.LeftMargin = sMrgn) And (.RightMargin = sMrgn) And (.TopMargin = sMrgn) And (.BottomMargin = sMrgn) Then
StrOut = "All margins"
Else
StrOut = "One or more margins not"
End If
End With
MsgBox StrOut & " equal to " & StrMrgn & " inches."
End Sub