• AutoText in Document (2002)

    Author
    Topic
    #381996

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #646132

      I don’t believe so, Kevin. The closest that I could think of accomplishing what you want is to create a macro in the document which would be portable… assuming the recipient enables the macros or runs on low security… shrug

      • #646448

        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.

        • #653197

          >> 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? smile

          • #653236

            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

            • #653263

              Chris,
              The difference here is that the autotext I’m creating is dynamic not static, so storing them
              in a global would not work.

              The cdev site is great. And their AutoText Manager is a fine product. I never had the spare
              time, but that’s what I wanted to write for years.

            • #653293

              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

            • #653295

              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!

            • #653375

              >That sounds pretty good. Care to share your code? I’d love to see
              >how you use “convert to htm”.

              I’ll see if I can package something up over the weekend and get is back here for next week.

              Chris

            • #653388

              Capital!

            • #658174

              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)

            • #658244

              Hi Chris:
              I thought this would be neat, but couldn’t get it to work in Word 97. The line
              (Visible:=False)
              says “Named argument not found”.

            • #658276

              Without a bit of recoding, Chris’ example code is not supported on
              Word 97.

              For starters, replace
              Set HTMDoc = Documents.Add(Visible:=False)

              with
              Set oApp = CreateObject(“Word.Application”)
              Set HTMDoc = oApp.Documents.Add

              But you’ll also need to code around other statements as well.

            • #658277

              Like Phil, I tried on a Word 97 install first. Will test later
              on XP. Thanks for your post. I’ll get back to you…

            • #658288

              Here’s the 97 version.

            • #658289

              You’re a peach, CD. Thanks.

              (love to take a closer look at that autotext manager of yours…) blackteeth

            • #658291

              My qucik looksee reveals that the stored autotext holds underline, but not bold formatting.
              Humm. That must have something to do with the fact that the text is stored as HTML, yes?

            • #658296

              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

            • #658755

              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

          • #653275

            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.)

            • #653310

              >> 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?

            • #653315

              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.

            • #653332

              >> 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.

            • #815263

              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.

            • #815264

              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.

    Viewing 0 reply threads
    Reply To: AutoText in Document (2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: