I have a form frmReplaceLinks that has a listbox on it lstFileLinkPaths set to mulitselectoption.
Currently the code below loops through the active document and changes all the OLE paths to that set in the variable strNewPath. This works fine, but I need to alter it so that it ONLY changes the OLE paths of those items selected in the listbox. I have had a few attempts in changing the code to do this but upto now no success. Any ideas?
Thanks
Sub SelectedChangeLinks()
Dim ilsh As InlineShape
Dim strFileName As String
Dim vParts As Variant
Dim vFileName As Variant
Dim lgCountOLE As Long
Dim lgStopCount As Long
Dim strNewPath As String
Dim i As Long
Dim errNum As Long
Dim fso As New Scripting.FileSystemObject
'ref to the Microsoft Scripting Runtime
Dim appBgdExcel As Object
Dim lgI As Long
Set appBgdExcel = New clsExcel 'speeds up the process by opening excel in the background
strNewPath = frmReplaceLinks.txtFindNew
LinkLocati
on.Value
lgCountOLE = 0
lgStopCount = 0
errNum = 0
'Counts the links
For Each ilsh In ActiveDocument.InlineShape
s
lgCountOLE = lgCountOLE + 1
Next ilsh
'Have to run from the bottom up otherwise creates a continous loop
For i = ActiveDocument.InlineShape
s.Count To 1 Step -1
Set ilsh = ActiveDocument.InlineShape
s(i)
StatusBar = "Updating " & i & " of " & lgCountOLE & " linked objects in this document..."
If ilsh.Type = wdInlineShapeLinkedOLEObje
ct Then
vParts = fso.GetParentFolderName(st
rNewPath)
vFileName = fso.GetFileName(strNewPath
)
On Error GoTo Err_ChangeLinks
'Error 6083 appears each time the following line is run, by
'repeating the line of code it then works???
ilsh.LinkFormat.SourceFull
Name = vParts & "\" & vFileName
errNum = 0
On Error GoTo 0
DoEvents
End If
Next i
StatusBar = "Links Updated...."
Call SetLinksManual
MsgBox "Update of links completed successfully" & vbLf & vbLf & _
lgCountOLE & " links were updated to the the file:" & vbLf & _
strNewPath & vbLf, vbInformation, "Updated Successfull"
Unload frmReplaceLinks
Exit Sub
Err_ChangeLinks:
If Err.Number = 6083 And errNum < 2 Then
errNum = errNum + 1
Resume
Else
Debug.Print Err.Number & " " & Err.Description
End If
End Sub