Trying to simulate a pause in VBA

J

JFW

I have looked at the article: http://support.microsoft.com/?kbid=212711

It appears to me that there is a bug in this code. When my BEFORE code is
Selection.TypeText("1")
and my AFTER code is
Selection.TypeText("2")

then repeat executions of the macro gives this result:

122122122122122122122122122122122122122122

If it were conducted properly, the result would be:

1212121212121212121212121212121212121212

For some reason it is taking two executions of the macro to clear the
keyboard assignation. Any idea why this is?

Also, I am interested in knowing if others have a similar result with the
repeating 122122122.

Thanks for your help.
 
J

Jean-Guy Marcil

JFW was telling us:
JFW nous racontait que :
I have looked at the article:
http://support.microsoft.com/?kbid=212711

It appears to me that there is a bug in this code. When my BEFORE
code is Selection.TypeText("1")
and my AFTER code is
Selection.TypeText("2")

then repeat executions of the macro gives this result:

122122122122122122122122122122122122122122

If it were conducted properly, the result would be:

1212121212121212121212121212121212121212

For some reason it is taking two executions of the macro to clear the
keyboard assignation. Any idea why this is?

Also, I am interested in knowing if others have a similar result with
the repeating 122122122.

Thanks for your help.

I am not very good with key assignments (I never really use them... my
clients always prefer toolbar buttons...)
I know there are some key assignment wizards hanging around, I am sure they
will have an explanation!

Meanwhile, I got it to work by doubling the line
FindKey(BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyA)).Disable
FindKey(BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyA)).Disable
and it is frustrating as I cannot tell why that solves the problem.


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
T

Tony Jollans

With all due respect to Microsoft, what a ridiculous piece of code! It is
trying (and failing) to use the presence of a KeyBinding as a flag and
describing the whole thing with a load of mumbo-jumbo.

The reason it doesn't work is that the Disable method disables (but does not
remove) an active keybinding. It does remove an already disabled one which
explains your results and Jean-Guy's workaround. To remove the keybinding
first time requires the Clear method ..

FindKey(BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyA)).Clear
 
J

Jean-Guy Marcil

Tony Jollans was telling us:
Tony Jollans nous racontait que :
With all due respect to Microsoft, what a ridiculous piece of code!
It is trying (and failing) to use the presence of a KeyBinding as a
flag and describing the whole thing with a load of mumbo-jumbo.

The reason it doesn't work is that the Disable method disables (but
does not remove) an active keybinding. It does remove an already
disabled one which explains your results and Jean-Guy's workaround.
To remove the keybinding first time requires the Clear method ..

FindKey(BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyA)).Clear

Thanks for that... I have never coded keybindings before as I have never had
the need..

Unfortunately, this is not the first time that a KB article code example is
all wrong...
The only thing in MSFT defence is that KB article are not always written by
MSFT people, but they are certainly approved by MSFT... so they should
always test/check whatever is proposed by the writer...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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