Microsoft Office Tutorials and References
In Depth Information
Copying Nested Field Codes as Text
Dim i As Long¶
Dim CurrChar As String¶
Dim CurrSetting As Boolean¶
Dim MyData As MSForms.DataObject¶
'Make the preparations¶
Set rng = Selection.Range¶
NewString = ""¶
Application.ScreenUpdating = False¶
'Make sure to pick up the field codes¶
rng.TextRetrievalMode.IncludeFieldCodes = True¶
FieldString = rng.Text¶
'Work through the characters in the selection, one-by-one¶
'and build the result. If a field opening or closing brace¶
'is encountered, put a brace-character in its place¶
For i = 1 To Len(FieldString)¶
CurrChar = Mid(FieldString, i, 1)¶
Select Case CurrChar¶
Case Chr(19)¶
CurrChar = "{"¶
Case Chr(21)¶
CurrChar = "}"¶
Case Else¶
End Select¶
NewString = NewString + CurrChar¶
Next i¶
'Put the result on the clipboard, so that¶
'the user can paste it wherever needed¶
Set MyData = New DataObject¶
MyData.SetText NewString¶
MyData.PutInClipboard¶
End Sub¶
Wrd
Select a field result (the entire result must be selected, not just an insertion
point), run the macro, then position the cursor where the field code should be
pasted.
Tip: This macro can also be used to paste into another application, such as an e-mail editor.
Note: Check that there is an active reference to the "Microsoft Forms 2.0 object
library" in Tools | References in the Visual Basic Editor. If you forget to take
this step, you’ll receive an error: User-defined type not defined. In this case,
stop the macro, add the reference, and try again.
Search JabSto ::




Custom Search