Help with Autotext

S

Sophia

Is there some kind of "Event" that can be tested for programmatically
.... one that occurs when an Autotext entry is inserted into a
document?

TIA
 
P

Peter Hewett

Hi Sophia

The short answer is no. There is a DocumentChange event but you can't tell
what has triggered the change. Also the event is called so often it could
cripple the application.

HTH + Cheers - Peter
 
S

Sophia

Thank you Peter, for being ever-present as I stumble through the
fog ...

I have a method, which I learned here or in one of the other Groups,
that allows me to open a UserForm by mapping the F3 key to open a
subroutine.

It works well enough, but I'd like to augment it by creating a means
by which a typist, seeing the appropriate Tool Tip pop up, could
simply press Enter at that point, thereby inserting the AutoText and
simultaneously opening the UserForm.

As it is now, the user is required to type the *entire* key (or
whatever you call it) that identifies the AutoText entry before
pressing F3. Some of the "keys" are rather long and to simply press
Enter when the proper Tool Tip appears would be convenient. It's not
*really* necessary to be able to do this, but it would be cool ...

Rgds,

Sophia
 
P

Peter Hewett

Hi Sophia

I'm not sure what the macro you've bound to the F3 key does other tham
display a UserForm, this is presumably a custom version of the standard
Word Insert>Autotext>Autotext dialog?

I don't know if the Autotext autocomplete mechanism has a special name but
there are three way of acccepting the suggested Autotext entry. You can use
the Tab, F3 and Enter keys.

It seems that you want to be able to press F3 to both accept the suggested
Autotext entry and then display a UserForm????

You could do this but the code would be pretty damn complex, because as far
as I know there's no mechanism for easily accessing the suggested Autotext
entry. Which means that you would have to design and write your own
algorithm to replicate what Word does inside you macro.

It's obviously possible but I'd hate to guess at how long it might take,
plus it's not beginners territory.

HTH + Cheers - Peter
 
S

Sophia

Peter ...

Hope you can make some sense of this ... nothing original here, it's
all snagged from one place or another in Usenet:

Public Sub Bind_F3_Key()

KeyBindings.Add KeyCategory:=wdKeyCategoryMacro,
KeyCode:=(BuildKeyCode(wdKeyF3)), Command:="NewAutoText"

End Sub

Public Sub NewAutoText()

Dim sourcedoc As Document
Application.ScreenUpdating = False
Selection.MoveLeft unit:=wdWord, Count:=1, Extend:=wdExtend
SelectionText = LCase(Selection.Text)
Selection.Delete

'LocateMacro SelectionText

ReadSourceTable SelectionText

On Error GoTo trap

Exit Sub

trap:
MsgBox "Make sure the word immediately preceding the cursor is
a known autotext entry.", vbCritical, "Autotext Error..."

End Sub

In "ReadSourceTable" there's a table lookup, which opens a UserForm

The whole thing is probably a convoluted mess, but it does work.

Regards,

Sophia
 
K

Klaus Linke

Hi Sophia,

You wouldn't really need to add a keybinding.
If you call the macro "Sub InsertAutoText()", it will intercept the built-in
command.
If you call it "Sub PrivFunctionKey3()", it will intercept the F3 key.

In the macro, you can call the built-in command with
"WordBasic.InsertAutoText".

I haven't a solution for your original question though.
I looked for a built-in command that might intercept the "enter" or "tab"
key in completing the AutoText entry, but didn't find anything.

One command that seemed a likely candidate didn't work out:
Dim myCBC As CommandBarControl
Set myCBC = CommandBars("Formatting").Controls.Add(ID:=2205)
MsgBox myCBC.TooltipText, , myCBC.DescriptionText
myCBC.Delete
(Pressing the button does seem to have no effect, and I didn't find a name
like "Sub ApplyAutoTextName()" with which to intercept the command)

Regards,
Klaus
 
S

Sophia

Thank you very much Klaus,

Very interesting! Sorry I didn't post here sooner, before I started
to do my Usnet searching.

I'm not sure what you mean by a "built-in command." Is there a list
of such things somewhere?

Rgds,

Sophia
 
K

Klaus Linke

Hi Sophia,
Very interesting! Sorry I didn't post here sooner, before I
started to do my Usnet searching.

Googling can't hurt...
I'm not sure what you mean by a "built-in command."
Is there a list of such things somewhere?

There's a list (for Word97) by Dave Rado at
http://word.mvps.org/faqs/general/CommandsList.htm

I've been meaning to make a new one for Word2003 for some time, but never
got around to it. A list I've done for Word2000/2002 is a 5 MByte table in
disarray, without even info on what command is available in which version,
or on any bugs and problems.

If you have the patience to scroll through "Tools > Macro > Macros... >
Macros in: Word commands", you'll find several commands relating to
AutoText: "AutoText", "CreateAutoText", "EditAutoText" and "InsertAutoText".
Those are (probably) the same commands that are run if you invoke the
AutoText commands from the user interface (with a keyboard shortcut, menu,
or toolbar control). You can see their description, or run them to check out
what they do.
By nature, only commands are listed that don't take arguments. Also, a lot
of the more exotic commands aren't listed (such as "PrivFunctionKey3"
mentioned in my last post).
Nevertheless, it often helps to scroll through the list to see what is
available as built-in functionality.

If you find a command here, you usually will find a button for the same
command in "Tools > Customize > Commands", though it may be hard to find
since you have to guess which button it is (... the name of the command
isn't listed; you have to go by the description).

If you click on a command in the list, switch to "Macros in: Normal.dot" or
another template, and "Create" a macro by the same name, your macro will run
instead of the built-in command. The created macro will usually already
contain the description and some code.

In case you do intercept a couple of built-in commands, it's a good idea to
put them in a separate module. It is easy to forget you have customized a
built-in command, and if Word starts acting weird, it may well be your code.

In old versions up to Word95, macro programming mostly consisted of running
the built-in commands through WordBasic code. But since the macro language
changed to VBA, there's hardly any official documentation. For old commands,
the Word95 help file can sometimes still be useful
(http://www.microsoft.com/downloads/release.asp?ReleaseID=26572).

Regards,
Klaus
 
P

Peter Hewett

Hi Sophia

To elaborate on what Klaus has said about built-in commands. Every time you
use Words menu, say File>New or Format>Paragraph Word is able to use a
userdefined macro to capture these menu or keyboard commands.

I'll explain how and maybe that will make sense. Suppose you want to
intercept File>New:

1. From Word (not the VBA IDE) press ALt+F8
2. In the "Macros in" dropdown select "Word commands"
3. Now select "FileNew" in the Word command listbox
4. In the "Macros in" dropdown select the template you want Word to create
the macro in
5. Click on the create button

Word will leave you in the VBA IDE with the new macro it created open. You
can now customise this macro to do what you want when a user of your
template selects File>New from Words menu.

You can intercept ALL of the commands listed, but beware Word can generate
completely empty macros that do nothing at all!!! If the macro you generate
in this way contains nothing but comments then be assured it's going to do
exactly nothing!!! Even worse if you leave the macro around then it
effectively disables the corresponding Word command, because it captures
that Word command and then does nothing with it!! I LOVE Word!!!

HTH + Cheers - Peter
 
P

Peter Hewett

Hi Sophia

Sorry, I'm not sure what you expect of me in respect to the posted code???

Cheers - Peter
 
S

Sophia

Sorry Peter,

I misread the message before that, thinking that you needed the code
to look at.

Thank you again for your ongoing help. You have the patience of a
saint.

Best,

Sophia
 
S

Sophia

AMAZING ... absolutely amazing. All that good stuff ... and I didn't
even know it was there.

(BTW, I'm using Word97) I'm thinking that I bought the wrong book
when I first got started in this, "Mastering Word6" by Sybex. I've
used their book on Access97 and been happy with it, but the Word book
is chatty ... written like WhateverForDummies and I find that there's
more chatter than solid instruction.

Could you recommend a book? (I can get the Word97 books used from
Amazon).

Thanks again for your meticulous instruction, code that works and
extraordinary patience.

Best,

Sophia
 
S

Sophia

Hi Klaus ...

Klaus ...

Hello Klaus,

Believe it or not, I'm a Certified Google Addict, but if you don't
know the generic *name* for something, all the Googling in the world
doesn't get too far ... or maybe *too* far, by listing thousands of
entries. I've also been to the MVPS site a zillion times, looking for
things I *did* know the names for, and have been enlightened every
time. I somehow missed the CommandsList, and thank you for sending me
there. The only commands I was aware of were the ones that appear in
the Help screens and in the Object Browser.

I do appreciate very much the time you took to lead me step-by-step
into the Magic Garden of the Officially Undocumented.

I was wondering if you could recommend a good book on Word97 VBA.
Even though my Word97 is somewhat of an antique, I can still get the
books used from Amazon (and at 25% of the original price).

I'm obviously lacking in some fundamentals, even after reading a
971-page book on the subject.

Thanks again for all your help,

Sophia
 
P

Peter Hewett

Hi Sophia

I can't really recommend a Word reference manual, I only every purchased one
and that was way back when for Word 6. Being an old programmer, like many
others, I've always done my own thing when it comes to exploring
applications.

I do have a couple of favourites for VBA though. A guy called Ken Getz wrote
or coauthored a couple of books for VBA and VBA/VB. When I first stared
messing with VBA/VB I found them lucid and useful! Both were publised by
Sybex, you may find used versions on Amazon/Barnes & Noble.

HTH + Cheers - Peter
 
K

Klaus Linke

Hi Sophia,
I was wondering if you could recommend a good book on Word97 VBA.

I'm much in the same situation as Peter: The few books I did buy are
catching dust.

The VBA help files are pretty good. For most stuff, they answer all
questions and have enough examples.
If that doesn't suffice, I usually do a Google search of the newsgroups,
then a search on http://word.mvps.org/Search/index.htm and
http://search.microsoft.com/search/search.aspx?View=en-us&st=a and, if all
fails, a web search on Google.

Greetings,
Klaus
 
C

Charles Kenyon

You might want to check out "Word 97 Annoyances."
--

Charles Kenyon

See the MVP FAQ: <URL: 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.
 
K

Klaus Linke

Charles said:
You might want to check out "Word 97 Annoyances."

I second that. It only contains a short introduction to Word VBA, but
(relating to this thread) it contains all 965 built-in commands in Appendix
B.
And it has a lot more useful info per square inch than those big, bloated,
700+ page Word books.

Greetings,
Klaus
 
P

Peter Hewett

Hi Sofia

Here's how to create a document containing a list of ALL Word commands (a
handy reference). You can do this from the VBA IDEs Immediate window or
create a little 1 line macro. Amyway, type (or paste) the following:
Application.Dialogs(wdDialogListCommands).Show

When the dialog is displayed, select "All Word commands">OK.

This is worth doing it's an amazing list. This can be done from within Word
but I've forgotten how to get to the dialog!!!!

HTH + Cheers - Peter
 
C

Charles Kenyon

Excellent hint. I created the document and added the code at the end in case
I want to re-run it on a different version of Word. Thank you.
--

Charles Kenyon

See the MVP FAQ: <URL: 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.
 

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