level 5
半个屁呼100斤
楼主
昨天录制了一个插入目录的宏,测试可行。但是今天打开同样的文件,运行同样的宏时却提示错误“5941”,

代码高亮:

这期间系统、文件、宏等一切设置均未发生改变。请教各位高手为何会出现这个问题,该如何解决?谢谢。
另有个新问题,在录制宏时,插入目录之后的“更新目录”命令不管是‘只更新页码’还是‘更新整个目录’的操作都无法被录制到宏里,单独录新宏也不行。请问这个问题怎么解决?谢谢。
宏代码下
Sub 宏1()
'
' 宏1 宏
'
'
Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1
Application.Templates( _
"C:\Users\William\AppData\Roaming\Microsoft\Document Building Blocks\2052\14\Built-In Building Blocks.dotx" _
).BuildingBlockEntries("自动目录 1").Insert Where:=Selection.Range, RichText _
:=True
Selection.InsertBreak Type:=wdPageBreak
Selection.WholeStory
Selection.Font.Color = wdColorAutomatic
Selection.HomeKey Unit:=wdStory
End Sub
2016年04月15日 02点04分
1




另有个新问题,在录制宏时,插入目录之后的“更新目录”命令不管是‘只更新页码’还是‘更新整个目录’的操作都无法被录制到宏里,单独录新宏也不行。请问这个问题怎么解决?谢谢。
宏代码下
Sub 宏1()
'
' 宏1 宏
'
'
Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1
Application.Templates( _
"C:\Users\William\AppData\Roaming\Microsoft\Document Building Blocks\2052\14\Built-In Building Blocks.dotx" _
).BuildingBlockEntries("自动目录 1").Insert Where:=Selection.Range, RichText _
:=True
Selection.InsertBreak Type:=wdPageBreak
Selection.WholeStory
Selection.Font.Color = wdColorAutomatic
Selection.HomeKey Unit:=wdStory
End Sub