Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-30-2014, 03:34 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

I think I'm making some progress and trying to replace the FilePath and FileName Separately, again as I think that is needed due to the charts needing the FileName twice in the link path.

Some of the code I found on line (Public FileName), but I've found the SourcePath and Sourcename are read only, and can't seem to replace them?



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
            MsgBox "The New File Path is: " & f.InitialFileName
            NewPath = f.InitialFileName & "\"
            '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
                    'MsgBox "The Existing FilePath is: " & .LinkFormat.SourcePath
                    OldPath = .LinkFormat.SourcePath
                    'MsgBox "The Existing File Name is: " & .LinkFormat.SourceName
                    OldFile = .LinkFormat.SourceName
                    
                    'Replace the FilePath
                    '.LinkFormat.SourcePath = NewPath
                    
                    'Replace the FileName
                    '.LinkFormat.SourceName = NewFile
                    
                    .Update
                End If
            End With
        Next x
    End With
    
    
End Sub

Public Function Filename(ByVal strPath As String) As String
    If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
        Filename = Filename(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
    End If
End Function
Reply With Quote
Reply



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 07:17 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