Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 11-30-2014, 04:05 PM
macropod's Avatar
macropod macropod is offline Word 2007 Edit Links to Files Windows 7 64bit Word 2007 Edit Links to Files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub UpdateLinks()
' This routine updates all external links, pointing them all to a single selected file.
' Turn Off Screen Updating temporarily.
Application.ScreenUpdating = False
Dim TrkStatus As Boolean, Pwd As String, pState As Boolean, StrFlNm As String
Dim Rng As Range, Fld As Field, Shp As Shape, iShp As InlineShape
' Select the new source file for the links
With Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
  .Title = "Select the new source file"
  .InitialFileName = ActiveDocument.Path
  .Filters.Clear 'clear filters
  .Filters.Add "Microsoft Excel Files", "*.xls, *.xlsb, *.xlsm, *.xlsx" 'filter for only Excel files
  .AllowMultiSelect = False
  If .Show = -1 Then
    StrFlNm = .SelectedItems(1)
  Else
    MsgBox "No new source file selected. Exiting", vbExclamation
    Exit Sub
  End If
End With
With ActiveDocument
  ' If used, insert your document's password between the double quotes on the next line
  Pwd = ""
  ' Initialise the protection state
  pState = False
  ' If the document is protected, unprotect it
  If .ProtectionType <> wdNoProtection Then
    ' Update the protection state
    pState = True
    ' Unprotect the document
    .Unprotect Pwd
  End If
  ' Store current Track Changes status, then switch off temporarily.
    TrkStatus = .TrackRevisions
    .TrackRevisions = False
  For Each Rng In .StoryRanges
    ' Go through the shapes in the story range.
    For Each Shp In Rng.ShapeRange
      With Shp
        ' Skip over shapes that don't have links to external files.
        If Not .LinkFormat Is Nothing Then
          ' Replace the link to the external file.
          .LinkFormat.SourceFullName = StrFlNm
        End If
      End With
    Next Shp
    ' Go through the inlineshapes in the story range.
    For Each iShp In Rng.InlineShapes
      With iShp
        ' Skip over inlineshapes that don't have links to external files.
        If Not .LinkFormat Is Nothing Then
          ' Replace the link to the external file.
          .LinkFormat.SourceFullName = StrFlNm
        End If
      End With
    Next iShp
    ' Go through the fields in the story range.
    For Each Fld In Rng.Fields
      With Fld
        ' Skip over fields that don't have links to external files.
        If Not .LinkFormat Is Nothing Then
          ' Replace the link to the external file.
          .LinkFormat.SourceFullName = StrFlNm
        End If
      End With
    Next Fld
  Next Rng
  ' Restore original Track Changes status
  ActiveDocument.TrackRevisions = TrkStatus
  ' If the document was protected, reprotect it, preserving any formfield contents
  If pState = True Then .Protect wdAllowOnlyFormFields, Noreset:=True, Password:=Pwd
  ' Set the saved status of the document to true, so that changes via
  ' this code are ignored. Since the same changes will be made the
  ' next time the document is opened, saving them doesn't matter.
  .Save
End With
' Restore Screen Updating
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
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 04:24 PM.


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