Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-03-2020, 10:08 AM
herodot herodot is offline How to replace field code with their values Windows 10 How to replace field code with their values Office 2016
Novice
How to replace field code with their values
 
Join Date: Jun 2020
Posts: 12
herodot is on a distinguished road
Default 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.
Attached Files
File Type: docx test.docx (53.9 KB, 5 views)
Reply With Quote
  #2  
Old 12-03-2020, 10:59 AM
Charles Kenyon Charles Kenyon is online now How to replace field code with their values Windows 10 How to replace field code with their values Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,138
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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
Reply With Quote
  #3  
Old 12-03-2020, 11:48 AM
herodot herodot is offline How to replace field code with their values Windows 10 How to replace field code with their values Office 2016
Novice
How to replace field code with their values
 
Join Date: Jun 2020
Posts: 12
herodot is on a distinguished road
Default

Holy cow, that was fast. It's working.


Thank you very much for the solution and your time, you helped me a lot.
Reply With Quote
  #4  
Old 12-03-2020, 11:55 AM
Charles Kenyon Charles Kenyon is online now How to replace field code with their values Windows 10 How to replace field code with their values Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,138
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

You are welcome. I've received a lot of help here and am "paying forward."
Stay safe.
Reply With Quote
Reply



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
How to replace field code with their values Find & Replace text in Field Code across multiple documents RPM7 Word VBA 6 05-12-2017 12:58 AM
How to replace field code with their values 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:05 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