#1
|
|||
|
|||
How to replace field code with their values
Hello!
I have word file and I would like to replace the field code with their actual values before sending to others to view it. My Field Code is { STYLEREF "Heading 5" \* MERGEFORMAT } and I would like to replace with its value, but every solution I found on the web, I didn't manage to make it work. Anw, I upload a simple preview file, if it would help you in any way. |
#2
|
|||
|
|||
This is called unlinking. Graham Mayor has examples on his site.
Microsoft Word Tips by Graham Mayor, MVP Code:
Sub UnlinkAllStyleRef() ' Unlink all StyleRef fields in a document, even if in headers/footers or textboxes ' Based on code at Installing Macros by Graham Mayor, MVP ' Charles Kenyon ' 3 December 2020 ' Dim oStory As range Dim oField As Field ' For Each oStory In ActiveDocument.StoryRanges For Each oField In oStory.Fields If oField.Type = wdFieldStyleRef Then oField.Unlink Next oField ' If oStory.StoryType <> wdMainTextStory Then While Not (oStory.NextStoryRange Is Nothing) Set oStory = oStory.NextStoryRange For Each oField In oStory.Fields If oField.Type = wdFieldStyleRef Then oField.Unlink Next oField Wend End If ' Next oStory ' Set oStory = Nothing Set oField = Nothing End Sub |
#3
|
|||
|
|||
Holy cow, that was fast. It's working.
Thank you very much for the solution and your time, you helped me a lot. |
#4
|
|||
|
|||
You are welcome. I've received a lot of help here and am "paying forward."
Stay safe. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA code to set xaxis chart values | MitzDriver | Office | 0 | 11-25-2017 10:58 AM |
code to find account and sum up values | Brian13 | Excel Programming | 2 | 05-31-2017 09:26 AM |
Find & Replace text in Field Code across multiple documents | RPM7 | Word VBA | 6 | 05-12-2017 12:58 AM |
VBA Code to search for field codes with certain text before the Field code and to change style | welcometocandyland | Word VBA | 4 | 02-08-2017 06:53 PM |
Lookup and replace cell values | rgauss | Excel | 3 | 10-03-2016 04:01 PM |