|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
在word中用宏进行页面设置时,如下一段代码,运行时错误'91':对象变量或with块变量未设置。请高手指教
Sub 页面设置()
Application.ScreenUpdating = False
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(2)
.BottomMargin = CentimetersToPoints(2)
.LeftMargin = CentimetersToPoints(2)
.RightMargin = CentimetersToPoints(2)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.5)
.FooterDistance = CentimetersToPoints(1.5)
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
.LayoutMode = wdLayoutModeDefault
End With
Dim ym As String, yj As String
'ym = InputBox("请输入页眉:", "页眉设置", "", 10, 20)
'yj = InputBox("请输入页脚:", "页脚设置", "", 10, 20)
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Delete
If ym <> "" Then
Selection.TypeText Text:=ym
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
Selection.WholeStory
Selection.Font.Size = 9
Selection.Font.Name = "宋体"
End If
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.WholeStory
Selection.Delete
If yj = "" Then Selection.TypeText Text:=" 第 " Else Selection.TypeText Text:=yj & " 第 "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
Selection.TypeText Text:=" 页"
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.WholeStory
Selection.Font.NameFarEast = "楷体_GB2312"
Selection.Font.NameAscii = "Times New Roman"
Selection.Font.Size = 9
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
|
|