![]() |
#8
|
|||
|
|||
![]()
Macropod.
I'm going to play more with the code you just posted, but I found an old post (by you actually ![]() your old post http://www.wordbanter.com/showthread.php?t=76379 So I am having success with the below code currently. The below will prompt for the new File and replace the FilePath and FileName Separately. It's pretty 'quick', replacing about 70 links in a few seconds. Code:
Sub ChangeFileLinks() Dim f As Object Dim i, x, fieldCount As Long Dim OldPath, OldFile As String Dim NewPath, NewFile As String Set f = Application.FileDialog(3) f.AllowMultiSelect = False If f.Show Then For i = 1 To f.SelectedItems.Count 'Get the File Path Only NewPath = f.InitialFileName NewPath = Replace(NewPath, "\", "\\") MsgBox "The New File Path is: " & NewPath 'Get the FileName only. Uses Public FileName Function Below MsgBox "The FileName Only is: " & Filename(f.SelectedItems(i)) NewFile = Filename(f.SelectedItems(i)) Next End If With ActiveDocument fieldCount = .Fields.Count For x = 1 To fieldCount With .Fields(x) 'Debug.Print .Type If .Type = 56 Then 'Get The Existing FilePath and File Name from the Link Sources OldPath = .LinkFormat.SourcePath & "\" OldPath = Replace(OldPath, "\", "\\") 'MsgBox "The Existing FilePath is: " & OldPath OldFile = .LinkFormat.SourceName 'MsgBox "The Existing File Name is: " & .LinkFormat.SourceName 'Replace the FilePath ' Replace the link to the external file .Code.Text = Replace(.Code.Text, OldPath, NewPath) '.LinkFormat.SourceFullName = NewPath 'Replace the FileName '.LinkFormat.SourceName = NewFile .Code.Text = Replace(.Code.Text, OldFile, NewFile) .Update End If End With Next x End With End Sub |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to fix/edit corrupted References in Word 2007 XP sv pk 3 | Hyper-Energy Bob | Word | 3 | 07-08-2014 02:00 PM |
How to copy linked Excel and Word files and retain links | ashleynpeters1 | Word | 1 | 05-30-2013 02:25 PM |
![]() |
btmna | Word | 2 | 01-31-2013 11:28 AM |
![]() |
nkg | Word | 1 | 02-19-2012 07:21 PM |
![]() |
tosti | PowerPoint | 5 | 01-31-2012 12:51 PM |