Changing Field Code to Text

V

Vince

I need to be able to change all the field codes in a document to text. I
read that I could simply select the text and press CTRL+SHIFT+F9 to make
this happen. It works when I do it manually. However, I need a macro to do
this. So, I did:

sub Mac
activedocument.select
sendkeys "^+{F9}"
end sub

Now, when I ran this, nothing happened. So, I tried a sendkeys "%F" to see
if the File Menu opened up. When I clicked the "Play" icon under VB editor,
the VB Editor's file menu opened up. When I did a Tools - Macro - Run - Mac,
nothing happened!

My question is how do I send the keys to Word or is there a better way...

Thanks for your time.

Vince
 
H

Helmut Weber

Hi,
hm..., seems CTRL+SHIFT+F9
replaces the field with the field result,
.... fields(1).unlink ...
not with the code.
For code you could use something like:

Dim s As String
s = ActiveDocument.Fields(1).Code
ActiveDocument.Fields(1).Select
Selection.Text = "{" & s & "}"

and loop through all fields.
You might have to check field.types,
which I omitted for simplicity.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
C

Charles Kenyon

The following should get most fields. Not sure about any you might have in
text boxes.

Note, though, that Page X of Y in headers footers will give you a fixed
number rather than the actual page number after you do this.

Private Sub FieldsUnlinkAllStory()
' All Story Field Unlinker
' Written by Charles Kyle Kenyon 9 December 2004
' repaired with help from Jezebel 10 December 2004
Dim oStory As Range
On Error Resume Next
For Each oStory In ActiveDocument.StoryRanges
Do
oStory.Fields.Unlink
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next
End Sub
 
V

Vince

Thank you Charles and Helmut. Works fine and I don't have any textboxes..

Thanks, again.
Vince
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top