|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 eh864166675 于 2023-6-1 11:42 编辑
录制代码如下:
Sub 插入页码()
'
' 插入页码 宏
'
'
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 = wdSeekCurrentPageFooter
With Selection.HeaderFooter.PageNumbers
.NumberStyle = wdPageNumberStyleNumberInDash
.HeadingLevelForChapter = 0
.IncludeChapterNumber = False
.ChapterPageSeparator = wdSeparatorHyphen
.RestartNumberingAtSection = False
.StartingNumber = 0
End With
Application.Templates( _
"C:\Users\admin\AppData\Roaming\Microsoft\Document Building Blocks\2052\16\Built-In Building Blocks.dotx" _
).BuildingBlockEntries("普通数字").Insert Where:=Selection.Range, RichText:= _
True
Selection.Font.Size = 14
Selection.Font.Name = "Times New Roman"
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Application.Templates( _
"C:\Users\admin\AppData\Roaming\Microsoft\Document Building Blocks\2052\16\Built-In Building Blocks.dotx" _
).BuildingBlockEntries("普通数字").Insert Where:=Selection.Range, RichText:= _
True
Selection.Font.Size = 14
Selection.Font.Name = "Times New Roman"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
运行时提示错误5941,调试定位错误为
Application.Templates( _
"C:\Users\admin\AppData\Roaming\Microsoft\Document Building Blocks\2052\16\Built-In Building Blocks.dotx" _
).BuildingBlockEntries("普通数字").Insert Where:=Selection.Range, RichText:= _
True
没学过wordvba,网上很少这个错误的资料,自动尝试抄作业未果,故来提问
|
|