|
附件如下:
添加目录.zip
(27.35 KB, 下载次数: 5)
想用excel打开同路径下的一个文件,并添加目录。用代码实现不了,请教大佬给纠正一下问题。
代码如下:
Private Sub CommandButton1_Click()
Dim appWD As Word.Application
Dim doc As Document
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
Set appWD = GetObject(, "Word.Application")
Set doc = GetObject(ThisWorkbook.Path & "\" & "测试文档.docx")
appWD.Visible = True
ActiveDocument.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:="", _
UseHyperlinks:=True, HidePageNumbersInWeb:=True, UseOutlineLevels:= _
True
ActiveDocument.TablesOfContents(1).TabLeader = wdTabLeaderDots
ActiveDocument.TablesOfContents.Format = wdIndexIndent
End Sub
|
|