开发者

How do you change the subdocument location in a Word 2007 master document programmatically?

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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜