Changing Links takes a LONG time

P

Paul Atkins

I wanted to write a macro to update the links to an Excel Spreadsheet to a
new Excel Spreadsheet, which I did do, and it works, but the macro takes an
incredibly long time (30-40 seconds) to execute the instruction:

aField.LinkFormat.SourceFullName = SourceFullName

As an aside, in changing the source, the fonts to fields annotated with \a
\f 5 \t yield text in a new font from the original document, and the \*
MERGEFORMAT tag in the original document has been removed. The document is
only 21 pages long and about 200k in size.

I'm using Word 2003 (11.6359.6360) SP1

Any ideas?

Thanks

==================================================================

Public Sub SetLinks()
Dim aField As Field
Dim SourceFullNameName As String
Dim LinkData() As String
Dim NewData() As String
Dim LinkCount As Integer
Dim Index As Integer
Dim FoundLink As Boolean

' First count the links to be processed
LinkCount = 0
For Each aField In ActiveDocument.Fields
If aField.Type = wdFieldLink Then
LinkCount = LinkCount + 1
End If
Next

' Redimension the LinkData array
ReDim LinkData(1 To LinkCount)
ReDim NewData(1 To LinkCount)

' Populate the LinkData array with LinkData
Index = 0
For Each aField In ActiveDocument.Fields
If aField.Type = wdFieldLink Then
Index = Index + 1
LinkData(Index) = aField.OLEFormat.Label
End If
Next

' Now, update all the links to the new path
SourceFullName = ActiveDocument.Path & "\" & _
Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 3) & "xls"

For Index = 1 To LinkCount
FoundLink = False
For Each aField In ActiveDocument.Fields
If Not FoundLink Then
If aField.Type = wdFieldLink Then
If aField.OLEFormat.Label = LinkData(Index) Then
aField.LinkFormat.SourceFullName = SourceFullName
'##################################
NewData(Index) = Format(Index, "##0. ") & _
aField.LinkFormat.SourceFullName & " " & _
aField.OLEFormat.Label
BreakHere = 1
FoundLink = True
End If
End If
End If
Next aField
Next Index
BreakHere = 2
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top