Results 1 to 1 of 1
  1. #1
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Lightbulb Field codes to text or string to allow posting - repost from macropod

    When discussing field codes in the forums or an email it can be helpful to actually see the code. When you copy a field code from Word and paste elsewhere (as in a forum) you simply get the field result.

    Related thread: Convert field codes to text for posting | Windows Secrets Lounge.

    Here is a similar macro from macropod. I've been using it since 2004 when I want to look at or share a field code. (Truly sharing a complex field code requires sending a document with the code in it, though.)

    Sub FieldCodeToString()
    ' Posted to the newsgroup on 15 April 2004 by macropod
    ' Converts a Word field code to a string (in the clipboard)
    '
    Dim Fieldstring As String, NewString As String, CurrChar As String
    Dim CurrSetting As Boolean, fcDisplay As Object
    Dim MyData As DataObject, X As Integer
    NewString = ""
    Set fcDisplay = ActiveWindow.View
    Application.ScreenUpdating = False
    CurrSetting = fcDisplay.ShowFieldCodes
    If CurrSetting <> True Then fcDisplay.ShowFieldCodes = True
    Fieldstring = Selection.Text
    For X = 1 To Len(Fieldstring)
    CurrChar = Mid(Fieldstring, X, 1)
    Select Case CurrChar
    Case Chr(19)
    CurrChar = "{"
    Case Chr(21)
    CurrChar = "}"
    Case Else
    End Select
    NewString = NewString + CurrChar
    Next X
    Set MyData = New DataObject
    MyData.SetText NewString
    MyData.PutInClipboard
    fcDisplay.ShowFieldCodes = CurrSetting
    MsgBox NewString & " is now in the Clipboard for pasting."
    End Sub

    Charles Kenyon
    Madison
    Last edited by Gary Frieder; 2011-07-29 at 11:27. Reason: Removed links - see Lounge Rule #12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •