如何以编程方式更改 Word 2007 主文档中的子文档位置?
我们遇到了令人不快的情况:由于目录重命名,各种主文档引用的子文档不再位于原来的位置。是否有一种编程方式可以调整 HYPERLINK 字段而不丢失主/子文档关系?
我已经到目前为止......
Sub FixyaLinks()
Dim s 'As String
Dim i As Long
Dim bTrackRevFlag As Boolean
Dim bShowRevFlag As Boolean
bTrackRevFlag = ActiveDocument.TrackRevisions
bShowRevFlag = ActiveDocument.ShowRevisions
ActiveDocument.TrackRevisions = False
ActiveDocument.ShowRevisions = False
For i = 1 To ActiveDocument.Fields.Count
s = ActiveDocument.Fields.Item(i).Code.Text
If InStr(s, "CURRICULUM\\NEW") Then
s = Replace(s, "NEW Foundation Units-in developing", "Foundation Programme Units")
ActiveDocument.Fields.Item(i).Code.Text = s
End If
Next
ActiveDocument.TrackRevisions = bTrackRevFlag
ActiveDocument.ShowRevisions = bShowRevFlag
End Sub
它在 ActiveDocument.Fields.Item(i).Code.Text = s
上爆炸,错误 5686(“操作无法完成,因为跟踪更改选项主文档中的选项与子文档中的选项不匹配。使主文档和子文档中的“跟踪更改”选项相同。”)但是,我不完全确定这意味着什么。
有人有想法吗?
We have had the unenviable happen: various master documents refer to sub-documents that are no longer where they used to be due to a directory renaming. Is there a programmatic way of tweaking the HYPERLINK field without losing the master/sub-document relationship?
I've got this far ...
Sub FixyaLinks()
Dim s 'As String
Dim i As Long
Dim bTrackRevFlag As Boolean
Dim bShowRevFlag As Boolean
bTrackRevFlag = ActiveDocument.TrackRevisions
bShowRevFlag = ActiveDocument.ShowRevisions
ActiveDocument.TrackRevisions = False
ActiveDocument.ShowRevisions = False
For i = 1 To ActiveDocument.Fields.Count
s = ActiveDocument.Fields.Item(i).Code.Text
If InStr(s, "CURRICULUM\\NEW") Then
s = Replace(s, "NEW Foundation Units-in developing", "Foundation Programme Units")
ActiveDocument.Fields.Item(i).Code.Text = s
End If
Next
ActiveDocument.TrackRevisions = bTrackRevFlag
ActiveDocument.ShowRevisions = bShowRevFlag
End Sub
It bombs on ActiveDocument.Fields.Item(i).Code.Text = s
, with an error 5686 ("The operation cannot be completed because the Track Changes option in the master document does not match the option the the subdocument. Make the Track Changes option the same in the master document and subdocument.") However, I'm not entirely sure what that means.
Ideas anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的代码和文章,我想说该错误基本上意味着您在运行主文档来修复它之前已经关闭了主文档中的跟踪更改,但是您正在更改的子文档链接已打开跟踪更改。
您是否尝试过打开轨道更改并更改链接?
您可能还应该测试您要修改的字段的种类。文档中可能还有其他类型的字段没有链接,并且您可能会无意中用此代码将它们弄乱。我认为你用 Field.Type 来做到这一点
Based on your code and writeup, I'd say that error basically means you've turned off track changes in the master before you run through it to fix it, but the subdoc link that you're altering has track changes on.
Have you tried turn ON track changes, and altering the link?
You also should probably test for the KIND of field that you're about to modify. There might be other kinds of fields in the document that AREN'T links, and you could mess them up inadvertently with this code. I think you do that with Field.Type