#1
|
|||
|
|||
Update Path of Field in Headers and Footers
I link fields from Excel to Word. What I am trying to do is be able to change the path of the fields in word and then update them through VBA. Once I get the code working, I will work on a user form, where the original and replacement path strings can be entered; however, I am getting ahead of myself. I have the following code, which works for the fields in the main body of word, but has no effect on the fields in the headers and footers. Any help on why it is not working would be greatly appreciated.
Sub ChangePathInLinkField() Dim doc As Word.Document Dim fld As Word.Field Dim rng As Word.Range Dim strSearchPath As String Dim strReplacePath As String Dim strNewFieldCode As String Set doc = ActiveDocument strSearchPath = "OldFilePath" strReplacePath = "NewFliePath" '' changes paths of fields in document '' For Each fld In doc.Fields If fld.Type = wdFieldLink Then strNewFieldCode = Replace(fld.Code.Text, strSearchPath, strReplacePath) fld.Code.Text = strNewFieldCode End If Next doc.Fields.Update '' changes paths of fields in header/footer '' For Each rng In doc.StoryRanges For Each fld In rng.Fields If fld.Type = wdFieldLink Then strNewFieldCode = Replace(fld.Code.Text, strSearchPath, strReplacePath) fld.Update End If Next fld Next rng End Sub |
#2
|
||||
|
||||
See the Word Fields and Relative Paths to External Files 'Sticky' thread at the top of the main Word forum: https://www.msofficeforums.com/word/...nal-files.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
headers/footers | scot | Word | 3 | 05-22-2015 09:45 AM |
Headers and Footers | Kingsmoss | Word | 3 | 04-28-2014 02:43 PM |
Odd and Even Headers/Footers | sarineochaos | Word | 1 | 02-04-2014 06:15 PM |
Headers and Footers | teza2k06 | Word | 1 | 05-14-2013 11:07 AM |
Headers and Footers | OverAchiever13 | Word | 1 | 05-27-2010 01:30 PM |