I was under the impression that Word 2002 allowed the storing of AutoText
in documents (as wll as in the attached template), but I can’t see how to do this.
Can it be done? I need “portable” autotext — available even when the template
is not.
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » AutoText in Document (2002)
Karen, thanks for the reply. That’s very strange. I thought for sure
I read that somewhere. Oh well. What I am trying to do is store
formatted text in a document variable –that is, hidden from the
user, but accessible programmatically so as to insert it at various
places in the document.
Currently I store the formatted text in autotext in a user’s Normal.dot (I once said
I’d never do this, but I can think of no other way). If that user sends the document to
another user, the formatted autotext is not available.. Maybe it’s possible to now store
formatted text in document variables. I doubt it.
>> Maybe it’s possible to now store formatted text in document variables. I doubt it. <<
I have an idea for you. I agree it's really bad to put this special AutoText into Normal.dot.
Couldn't you write a Rich2Tags "parser" which would pass through the formatted text looking at a limited number of things:
– Font size
– Italics, Bold, Underlined
– Line breaks
– Tabs (hmm… ASCII 9 characters are no problem, but tab settings could be rough)
And then convert the formatted text into a kind of "tagged" plain text which could be put into the document variables.
In other words, why not store this in the document variable:
I'm KevinI live in Hollywood.
Then when it’s time to access the formatted text programmatically, you have a Tags2Rich parser routine, which goes through and reconstitutes the tags back into Rich text.
I’m Kevin
I live in Hollywood.
For most purposes, your Rich2Tags and Tags2Rich routines wouldn’t have to support all that many kinds of formatting beyond the basics.
The funny thing is, I’m doing the exact same kind of centralized document automation project that you’re working on (you mentioned it in a post in November), to eliminate most templates and instead have few templates with an intelligent DLL or COM Add-In do all the work. When I saw your November post just now, I got all excited and I was just in the process of going through and reading all your posts! After I’ve read all your posts, I’m going to want to ask you a few things. (I’ll put those in another post)
I just have to make a bad pun: When you actually insert the text (above) into Word, it’s a kind of Tags to Riches story, ain’t it?
My approach is to create a library of autotext in a global addin template (or series of templates). These can be centrally stored which means there is only one point of maintenance. Of course all users have to have these global addins loaded in order to use the autotext. Its not a perfect solution but better than using Normal.dot.
If interested look at Autotext Manager in http://www.cdev.co.uk
Chris
Kevin, Geoff
It is a good idea to store the formatted text in a Doc Var as tagged text.
I have produced a macro to store formatted text in a database as html tagged asci text and this is a similar issue, I used Word’s own ‘convert to htm’ to do the job, as Kevin has mentioned. Doing it in RTF sounds harder.
The main problem is that formatting is not particularly well preserved.
You could always send the document out as a template masquerading as a document. Ouch!
Chris
Chris,
That sounds pretty good. Care to share your code? I’d love to see
how you use “convert to htm”. As Goeff seemed to know, my formatting
needs are rather limited: just some underlining and occassional bolding.
So, if you’ve got some kind of parser/converter, you might just be the lucky winner!
A bit late… but here is the DocAutotext method. (Word 2000 tested.)
Open the document DocAutotext.doc.
Select some text and press the SetAutotext button, give it a name eg fred.
Go to the end of the document and press Insert Autotext, named fred or whatever.
Let me know how it goes for you.
Chris (chris@cdev.co.uk)
Kevin
Look at the code line:
Const TEMPDOCNAME As String = “$temp$.rtf” ‘===============> use .rtf for RTF or .htm for HTML formatting
change the .rtf to .htm and that results in htm being used as the formatting/tagging method (Word 2000 and XP only).
See how that affects the formatting. Horribly verbose though isnt it? 30K for a bit of formatted text! The next stage would be to strip down the htm/rtf codes down to only the body part.
Chris
Chris,
This is cool. I had a need for something like this too.
I observed a couple of other things you may want to consider if ever revising this:
– if you choose an existing name for the new AT, the old value of that AT entry is overwritten with NO warning
– when inserting AT, no list of items. Can this be fixed bcs of next item?
– if name does not exist on insert, get a debug error
I did wonder why 15 or so characters took up over 3K bytes.
Fred
Geoff,
Great to hear from you. I like the way you think. Hummm. That is a great idea.
Let me see if I can get my brain around that one.
I see one immediate problem with your idea: How do you
produce that rich text without a document or richtext control? If Word were “tag-based”,
like WordPerfect I can see it quite easily. But Word needs some container for rich text
and that means a document or richtext control – visual controls — what we need is
a non-visual control. MS, are you listening???
I do admit that there may be such a thing floating around that will work, but I’m not
aware of it.
How about letting Word decifer html tags in order to produce the rich text?
Office 11 will do that nicely with XML, but Office 10? I don’t know. I’ll have to test.
As for your future posts: post away!
p.s. I only live in Hollywood when I’m filming…all other times I live in Hollyword. (Hey one bad pun
deserves another.)
>> How do you produce that rich text without a document or richtext control? <<
But we do have a document, don't we? Your initial quest was "to store Rich text in a document variable," right? So presumably there is the document you're taking that value from.
I think the Tags2Rich parser would take the plain ASCII value stored in the document variable and recreate the Rich Text within the Active Document using Selection.TypeText right there in place within the document.
OTOH, if your preference is to create a new AutoText entry dynamically, and not necessarily insert the Rich Text into the Active Document, I have another idea. Perhaps you want to let your user insert that AutoText when and where and if she pleases.
Here's my other idea…
Turn ScreenUpdating off, and Add a document. Do all your dirty work (uh, I mean, create the Rich Text!), and then SelectAll, and create the AutoText entry, and then Close the ActiveDocument.
‘ Take care of the user interface needs —————————————
System.Cursor = wdCursorWait ‘Set the hourglass cursor
Application.ScreenUpdating = False ‘Turn screen updating OFF
StatusBar = “Generating Dynamic Autotext…” ‘Might be nice to fill in the status bar
‘ Prepare environment and remember setting ——————————-
Documents.Add ‘Ensure we have a clean document
bDidFCShow = ActiveWindow.View.ShowFieldCodes ‘Remember users field code option
Selection.Collapse ‘Ensure there is no selection
ActiveWindow.View.ShowFieldCodes = False ‘So we do not see field codes
‘ Get to work creating required Rich Text ————————————–
‘ ….
Selection.TypeText “Do dirty work of Tags2Rich!”
Selection.TypeText “Step thru ASCII text from Document Variable, etc….”
‘ ….
‘ Make the AutoText entry ————————————————————
Selection.WholeStory
NormalTemplate.AutoTextEntries.Add Name:=”DynamicAutoTextOfMine”, Range:= Selection.Range
‘ Clean up ——————————————————————————–
ActiveWindow.View.ShowFieldCodes = bDidFCShow ‘Restore user’s field codes option
ActiveDocument.Close savechanges:=wdDoNotSaveChanges ‘Get rid of temporary doc
‘ Take care of user interface again ———————————————————————
System.Cursor = wdCursorNormal ‘Set a normal cursor
Application.ScreenUpdating = True ‘Turn screen updating ON
StatusBar = “” ‘clear the status bar
Is that what you meant?
This is pretty much the way I am doing it now. But i don’t like it.
Pasting in text at the IP or creating a hidden document, then formatting
the text using all manner of parsing techniques to find the text that
needs the formatting, etc, etc. then storing that in autotext in the user’s
normal.dot is not my idea of a good time.
Your idea of tagged text in a doc var is champion. But getting the text from
tagged docvar values to document formatted text — that’s the sticky wicket.
My hope is that pasted XML will “convert” to formatted text in Office 11.
>> using all manner of parsing techniques to find the text that needs the formatting, etc, etc. then storing that in autotext in the user’s normal.dot is not my idea of a good time. <> But getting the text from tagged docvar values to document formatted text — that’s the sticky wicket. <<
Following up on the other possibility (DocVar value is in RTF format)…
When you want to create the actual AutoText entry (you should turn off ScreenUpdating, etc. as before), here's what I envision…
1. grab the RTF from the DocVar and put it into a string sTEXTFROMDOCVAR
2. write the contents of the DocVar to a file using plain ole BASIC sequential file statements
Open "c:temp.rtf" For Output As #1
Print #1, sTEXTFROMDOCVAR
Close #1
3. open the "temp.rtf" file using Word's FileOpen command
4. Select the WholeStory
5. create the AutoText in the NormalTemplate
6. close "temp.rtf" file
7. delete "temp.rtf" file
Two additional thoughts:
A. If you took this approach, you might not want to write the "temp.rtf" to "c:" in a hardcoded manner like I showed. It would be better to grab the user's Personal or Temp directory from the Registry "ShellFolders" or using the API and write it there. A person may not have rights to "c:", say if they were working on a Terminal Server.
B. You might be able to avoid creating a "temp.rft" file all together if you muck around with DataObject or the Clipboard and get MS Word to recognize the RTF string as the correct Rich Text datatype.
Over a year late in this post, but has anybody tried the {PRIVATE} field to hold tagged text with any kind of formatting characteristics?
I have used this extensively to convert a parsed XML file into a decently formatted Word file with zillions of embedded {Private} fields. Including tabular matter, footnotes, endnotes, special characters beyond the ASCII character set (which necessitates use of Unicode, and hence eliminates Word 97 for the solution). And what’s more, a single macro then allows me to “round-trip” and generate a completely valid XML file as output. However, this means writing a separate set of macros (XML2Word & Word2XML) for each DTD. See a more detailed description of this case study here.
Over a year late in this post, but has anybody tried the {PRIVATE} field to hold tagged text with any kind of formatting characteristics?
I have used this extensively to convert a parsed XML file into a decently formatted Word file with zillions of embedded {Private} fields. Including tabular matter, footnotes, endnotes, special characters beyond the ASCII character set (which necessitates use of Unicode, and hence eliminates Word 97 for the solution). And what’s more, a single macro then allows me to “round-trip” and generate a completely valid XML file as output. However, this means writing a separate set of macros (XML2Word & Word2XML) for each DTD. See a more detailed description of this case study here.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.