如何设置word文档页面?



我已经使用VBA代码在Excel应用程序中创建了一个表格,并将相同的表格复制到word文档中,这里的问题是我想更改word文档页面设置,任何人都可以更正我的代码。 谢谢。。。

Sub word_page_setup()
With Documents("Document1.doc").pagesetup
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
End With
End Sub

假设您要在名为 Document1.doc 的文档中设置边距,这将完成。

Option Explicit
Sub word_page_setup()
Dim doc As Document
Dim doctest As Document
Dim doccol As Documents
Set doccol = Documents
' find the document named Document1.doc
For Each doctest In Documents
If doctest.Name = "Document1.doc" Then Set doc = doctest
Next
' if we didn't find it then exit
If doc Is Nothing Then Exit Sub
' set margins
With doc.PageSetup
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
End With
End Sub

最新更新