How do you change the subdocument location in a Word 2007 master document programmatically?
Posted
by boost
on Stack Overflow
See other posts from Stack Overflow
or by boost
Published on 2010-05-21T06:44:15Z
Indexed on
2010/05/21
6:50 UTC
Read the original article
Hit count: 327
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?
© Stack Overflow or respective owner