Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 11-30-2014, 04:09 PM
ptmuldoon ptmuldoon is offline Word 2007 Edit Links to Files Windows 7 64bit Word 2007 Edit Links to Files Office 2013
Advanced Beginner
Word 2007 Edit Links to Files
 
Join Date: Sep 2014
Posts: 93
ptmuldoon is on a distinguished road
Default

Macropod.

I'm going to play more with the code you just posted, but I found an old post (by you actually ) that used code.text in the replace.
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
Reply With Quote
 



Similar Threads
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
Word 2007 Edit Links to Files Edit text in a picture on word 2007 btmna Word 2 01-31-2013 11:28 AM
Word 2007 Edit Links to Files Edit Links Command Selection nkg Word 1 02-19-2012 07:21 PM
Word 2007 Edit Links to Files Batch Edit Links tosti PowerPoint 5 01-31-2012 12:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:43 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft