Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-28-2020, 11:09 AM
lisa99 lisa99 is offline Update Path of Field in Headers and Footers Windows 10 Update Path of Field in Headers and Footers Office 2016
Novice
Update Path of Field in Headers and Footers
 
Join Date: Jun 2018
Posts: 2
lisa99 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 04-28-2020, 02:51 PM
macropod's Avatar
macropod macropod is offline Update Path of Field in Headers and Footers Windows 7 64bit Update Path of Field in Headers and Footers Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

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]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Path of Field in Headers and Footers headers/footers scot Word 3 05-22-2015 09:45 AM
Update Path of Field in Headers and Footers Headers and Footers Kingsmoss Word 3 04-28-2014 02:43 PM
Update Path of Field in Headers and Footers Odd and Even Headers/Footers sarineochaos Word 1 02-04-2014 06:15 PM
Update Path of Field in Headers and Footers Headers and Footers teza2k06 Word 1 05-14-2013 11:07 AM
Headers and Footers OverAchiever13 Word 1 05-27-2010 01:30 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:49 PM.


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