Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Changing Field Code to Text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vince - 22 Dec 2004 02:39 GMT
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
Helmut Weber - 22 Dec 2004 09:11 GMT
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
Charles Kenyon - 22 Dec 2004 16:15 GMT
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

Signature

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

>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
[quoted text clipped - 18 lines]
>
> Vince
Vince - 23 Dec 2004 03:07 GMT
Thank you Charles and Helmut. Works fine and I don't have any textboxes..

Thanks, again.
Vince
> The following should get most fields. Not sure about any you might have in
> text boxes.
[quoted text clipped - 38 lines]
> >
> > Vince

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.