K
KC VBA Qns
Hi,
I am new boy to the block, especially to Word VBA I am a new born.
This is the all time referenced solution by Doug Robbins created on
26/10/01 to updating ALL the links to Excel sources in a Word doc in
one simple step. I tried and the end result is that ALL links,
originally referencing to different Excel files, are now pointing to
the one and only one common Excel file.
Could someone help tweak the codes so as to check, summarize and prompt
users to change only for the unique sources?
Dim alink As Field, linktype As Range, linkfile As Range
Dim linklocation As Range, i As Integer, j As Integer, linkcode As
Range
Dim Message, Title, Default, Newfile
Dim counter As Integer
counter = 0
For Each alink In ActiveDocument.Fields
If alink.Type = wdFieldLink Then
Set linkcode = alink.Code
i = InStr(linkcode, Chr(34))
Set linktype = alink.Code
linktype.End = linktype.Start + i
j = InStr(Mid(linkcode, i + 1), Chr(34))
Set linklocation = alink.Code
linklocation.Start = linklocation.Start + i + j - 1
If counter = 0 Then
Set linkfile = alink.Code
linkfile.End = linkfile.Start + i + j - 1
linkfile.Start = linkfile.Start + i
Message = "Enter the modified path and filename
following this Format " & linkfile
Title = "Update Link"
Default = linkfile
Newfile = InputBox(Message, Title, Default)
End If
linkcode.Text = linktype & Newfile & linklocation
counter = counter + 1
End If
Next alink
Rgds,
I am new boy to the block, especially to Word VBA I am a new born.
This is the all time referenced solution by Doug Robbins created on
26/10/01 to updating ALL the links to Excel sources in a Word doc in
one simple step. I tried and the end result is that ALL links,
originally referencing to different Excel files, are now pointing to
the one and only one common Excel file.
Could someone help tweak the codes so as to check, summarize and prompt
users to change only for the unique sources?
Dim alink As Field, linktype As Range, linkfile As Range
Dim linklocation As Range, i As Integer, j As Integer, linkcode As
Range
Dim Message, Title, Default, Newfile
Dim counter As Integer
counter = 0
For Each alink In ActiveDocument.Fields
If alink.Type = wdFieldLink Then
Set linkcode = alink.Code
i = InStr(linkcode, Chr(34))
Set linktype = alink.Code
linktype.End = linktype.Start + i
j = InStr(Mid(linkcode, i + 1), Chr(34))
Set linklocation = alink.Code
linklocation.Start = linklocation.Start + i + j - 1
If counter = 0 Then
Set linkfile = alink.Code
linkfile.End = linkfile.Start + i + j - 1
linkfile.Start = linkfile.Start + i
Message = "Enter the modified path and filename
following this Format " & linkfile
Title = "Update Link"
Default = linkfile
Newfile = InputBox(Message, Title, Default)
End If
linkcode.Text = linktype & Newfile & linklocation
counter = counter + 1
End If
Next alink
Rgds,