Templates 在SharePoint上的Word模板中更改带有宏的标题

Templates 在SharePoint上的Word模板中更改带有宏的标题,templates,sharepoint,macros,header,Templates,Sharepoint,Macros,Header,我正在开发一个Word模板,用户可以从Sharepoint访问该模板。 在这个模板中,我用自定义ui编辑器创建了一个自定义功能区 我希望用户能够选择页眉和页脚。 为此,我已经制作了2个不同的标题(1个有字段,1个没有),并将它们保存在模板中。 因此,当我想插入标题时,我可以这样选择它们:插入-->标题-->向下滚动到“模板”并选择其中一个。这很好用。我已录制了此过程的宏,因此可以在自定义功能区上使用此宏 宏如下所示: Sub Header() If ActiveWindow.View.Split

我正在开发一个Word模板,用户可以从Sharepoint访问该模板。 在这个模板中,我用自定义ui编辑器创建了一个自定义功能区

我希望用户能够选择页眉和页脚。 为此,我已经制作了2个不同的标题(1个有字段,1个没有),并将它们保存在模板中。 因此,当我想插入标题时,我可以这样选择它们:插入-->标题-->向下滚动到“模板”并选择其中一个。这很好用。我已录制了此过程的宏,因此可以在自定义功能区上使用此宏

宏如下所示:

Sub Header()
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
Application.Templates( _
    "http://spf.mysite.be/Shared%20Documents/Template.dotm"). _
    BuildingBlockEntries("Header").Insert Where:=Selection.Range, _
     RichText:=True
Selection.MoveDown Unit:=wdLine, count:=4
Selection.Delete Unit:=wdCharacter, count:=1
Selection.Delete Unit:=wdCharacter, count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
子标题()
如果ActiveWindow.View.SplitSpecial WDPaneOne,则
活动窗口。窗格(2)。关闭
如果结束
如果ActiveWindow.ActivePane.View.Type=wdNormalView或ActiveWindow_
ActivePane.View.Type=wdOutlineView然后
ActiveWindow.ActivePane.View.Type=wdPrintView
如果结束
ActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageHeader
应用程序.模板(_
"http://spf.mysite.be/Shared%20Documents/Template.dotm"). _
BuildingBlockEntries(“标头”)。插入其中:=Selection.Range_
RichText:=True
Selection.MoveDown单位:=wdLine,计数:=4
选择。删除单位:=wdCharacter,计数:=1
选择。删除单位:=wdCharacter,计数:=1
ActiveWindow.ActivePane.View.SeekView=WDSeekIndocument
端接头
问题是: 当我从sharepoint打开模板时,此宏不再工作。 我认为这是因为Word更改了链接模板。当我转到“开发人员”选项卡并单击“文档模板”时,链接的模板如下:“C:\Users\xxx\AppData\Local\Temp\TemplateATA-8.dotm”(下次从SharePoint打开模板时,8更改为9) 当我在本地工作并将链接更改为本地位置时,没有问题

有人能帮我吗? 谢谢 尼娜


(我正在使用Word 2013,但旧版本的Word也必须能够使用该文档。)

问题已解决。我将链接更改为:
Application.Templates(_
ActiveDocument.AttachedTemplate.FullName)_
现在它工作得很好