Change all links' sources in a Word document - Misplacement of Ranges

后端 未结 2 873
名媛妹妹
名媛妹妹 2021-01-11 17:56

I work on this code to change the sources of all linked Fields/Charts/... in Word templates to the workbook it is launched from.

I had usual

2条回答
  •  孤街浪徒
    2021-01-11 18:45

    Maybe not all Fields/Shapes are linked and the original insert of the field/shape resulted in not all properties being created on the object.

    To advance your code and find out in more detail what is the matter with the objects, try to ignore and report errors. Use watches to inspect the objects.

    For example:

    On Error Goto fieldError
    For Each aField In oDoc.Fields
        With aField
            .LinkFormat.AutoUpdate = False
            DoEvents
            .LinkFormat.SourceFullName = NewLink
            .Code.Text = Replace(.Code.Text, Replace(.LinkFormat.SourceFullName, "\", "\\"), Replace(NewLink, "\", "\\"))
            Goto fieldContinue
          fieldError:
            MsgBox "error: "
          fieldContinue:
        End With
    Next aField
    

    P.s.: what is the purpose of DoEvents? That will process external events (Windows messages).

提交回复
热议问题