|
在本论坛里面检索到一篇将doc文档拆分的帖子,链接如下:
http://club.excelhome.net/thread-1077899-1-1.html
Sub Split()
Const strFileExtension = ".docx"
Dim oSection As Section
Dim strTargetFileName As String
For Each oSection In ActiveDocument.Sections
strTargetFileName = Replace(ActiveDocument.FullName, strFileExtension, "_" & oSection.Index & strFileExtension)
oSection.Range.ExportFragment strTargetFileName, wdFormatDocumentDefault
Next
MsgBox "完成!"
End Sub
但是里面拆分后的文档是用章节的序号(oSection.Index)重命名,我想将这里改成以章节的首页页眉重命名,
在查看了官方的帮助之后,用msgbox命令确认了页眉内容的宏写法如下:
oSection.Headers(wdHeaderFooterFirstPage).Range.Text
写完之后的宏为:
Sub Split()
Const strFileExtension = ".docx"
Dim oSection As Section
Dim strTargetFileName As String
For Each oSection In ActiveDocument.Sections
strTargetFileName = Replace(ActiveDocument.FullName, strFileExtension, "_" & oSection.Headers(wdHeaderFooterFirstPage).Range.Text & strFileExtension)
oSection.Range.ExportFragment strTargetFileName, wdFormatDocumentDefault
Next
MsgBox "完成!"
End Sub
但是上述宏运行之后出错,提示为上面黄色背景
由于是初学者,不知道如何调试,所以请那位帮我调试一下,谢谢!!
|
|