Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-12-2017, 08:13 AM
ugcheleuce ugcheleuce is offline Convert raw field codes to plain text and back again Windows 7 64bit Convert raw field codes to plain text and back again Office 2003
Novice
Convert raw field codes to plain text and back again
 
Join Date: Mar 2014
Location: Netherlands
Posts: 24
ugcheleuce is on a distinguished road
Post Convert raw field codes to plain text and back again

Hello everyone

Is there a way to convert raw field codes to plain text, and later back again to field codes? I'm using Word 2003, but a solution for Word 2016 would also be fine.

What I mean is this:

Suppose you add a SYMBOL field code with the value of 111. If field code display is disabled, it will show up as the letter "o", but if field code display is enabled, it will show up as { SYMBOL 111 \* MERGEFORMAT }.

I want to convert the "{ SYMBOL 111 \* MERGEFORMAT }" to plain text (so that I can save the file as TXT, for example). Then, later, I want to open the TXT file in Word and convert the "{ SYMBOL 111 \* MERGEFORMAT }" text into an actual field code.

I want to do this because I want to process a certain type of MS Word file in an external program that handles only plain text files.

Thanks!
Samuel
Reply With Quote
  #2  
Old 02-12-2017, 04:19 PM
macropod's Avatar
macropod macropod is offline Convert raw field codes to plain text and back again Windows 7 64bit Convert raw field codes to plain text and back again Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

To convert field codes to text, you could use the following macro:
Code:
Sub FldCodeToStr()
Application.ScreenUpdating = False
Dim StrFld As String, StrTxt As String, StrChr As String, bFldShw As Boolean, i As Long
StrTxt = "": bFldShw = ActiveWindow.View.ShowFieldCodes
ActiveWindow.View.ShowFieldCodes = True
StrFld = Selection.Text
For i = 1 To Len(StrFld)
  StrChr = Mid(StrFld, i, 1)
  Select Case StrChr
    Case Chr(19)
      StrChr = "{"
    Case Chr(21)
      StrChr = "}"
    Case Else
  End Select
  StrTxt = StrTxt + StrChr
Next
Selection.TypeText StrTxt
ActiveWindow.View.ShowFieldCodes = bFldShw
Application.ScreenUpdating = True
End Sub
To reverse the process, see Convert Text Representations of Fields to Working Fields in the Mailmerge Tips and Tricks thread in the Mailmerge forum:
https://www.msofficeforums.com/mail-...ps-tricks.html
The code there turns a text representation of a field code into a working field. Not only does it do so for fields represented via parenthetic expressions (i.e. { }) but also for mergefields represented by chevrons (i.e. « »).

Do note that both processes lose any formatting the applied to the content within quoted strings or via the Charformat switch. If the retention of such formatting is required, it is advisable to run it on a copy of any such fields so the formatting can be restored post-conversion.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-12-2017, 09:56 PM
gmayor's Avatar
gmayor gmayor is offline Convert raw field codes to plain text and back again Windows 10 Convert raw field codes to plain text and back again Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

See http://www.gmayor.com/export_field.htm which does the conversion in both directions.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #4  
Old 02-14-2017, 05:03 AM
ugcheleuce ugcheleuce is offline Convert raw field codes to plain text and back again Windows 7 64bit Convert raw field codes to plain text and back again Office 2003
Novice
Convert raw field codes to plain text and back again
 
Join Date: Mar 2014
Location: Netherlands
Posts: 24
ugcheleuce is on a distinguished road
Default

Thank you, both, for your helpful answers.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert raw field codes to plain text and back again Macro Needed To Convert Text in Word to Plain Text and Back to Word rsrasc Word VBA 5 12-18-2015 07:13 AM
Convert raw field codes to plain text and back again Convert image-text hybrids into plain text morlack Excel 4 12-03-2014 05:29 PM
Converting field codes to plain text Jennifer Murphy Word 6 08-20-2014 05:10 AM
My plain text post got converted to rich text in a reply, how to convert it back? david.karr Outlook 0 01-05-2012 09:46 AM
Convert LISTNUM field codes to text remedios43 Word 2 07-31-2011 09:21 AM

Other Forums: Access Forums

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