Shortcut key doesn't run macro properly

V

Vivian Carroll

In Word 2000 I have a macro in an Add-in template that finds the next @
symbol. It moves one character to the right before performing the Find in
case an @ symbol is currently selected.

The macro works correctly when run from the VBE or from a toolbar button.
However, when run from the Alt+2 shortcut, it does not move right before
performing the Find (so once it has found the first @, it stays on that @
each time Alt+2 is pressed). The weird thing is that if the template itself
is opened, Alt+2 works correctly on text inserted into the template - it
just doesn't work in other documents.

What is the explanation for this and how can I make Alt+2 work correctly?

TIA,
Vivian Carroll
 
W

Word Heretic

G'day "Vivian Carroll" <[email protected]>,

dont move to the right, collapse to the end

ensure you select the find result.


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Vivian Carroll reckoned:
 
V

Vivian Carroll

Thanks, but I forgot to mention that collapsing to the end has the same
result.
 
W

Word Heretic

G'day "Vivian Carroll" <[email protected]>,

I'll need to see a code sample

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Vivian Carroll reckoned:
 
V

Vivian Carroll

Hi Steve, Here's the entire macro...

With Selection
.MoveRight Unit:=wdCharacter, Count:=1
With .Find
.ClearFormatting
.Text = "@"
.Forward = True
.Wrap = False
.Execute
End With
.Extend Character:="]"
End With


Vivian
 
W

Word Heretic

G'day "Vivian Carroll" <[email protected]>,

I see numerous problems here. As you are using selection.find there is
no guarentee there arent options set by the user via the GUI.

1) No Matchwildcards=False (@) is a wildcard

2) Tthe keypress seems to be interfering. Change Selection to MyRange
and do this at the start

Dim MyRange as Range

Set MyRange = Selection.Range.Duplicate

and at the end do a MyRange.Select


It's just a workaround


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Vivian Carroll reckoned:
Hi Steve, Here's the entire macro...

With Selection
.MoveRight Unit:=wdCharacter, Count:=1
With .Find
.ClearFormatting
.Text = "@"
.Forward = True
.Wrap = False
.Execute
End With
.Extend Character:="]"
End With


Vivian

Word Heretic said:
G'day "Vivian Carroll" <[email protected]>,

I'll need to see a code sample

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Vivian Carroll reckoned:
 
V

Vivian Carroll

Thanks Steve,

I'll have to study ranges more!

Vivian

Word Heretic said:
G'day "Vivian Carroll" <[email protected]>,

I see numerous problems here. As you are using selection.find there is
no guarentee there arent options set by the user via the GUI.

1) No Matchwildcards=False (@) is a wildcard

2) Tthe keypress seems to be interfering. Change Selection to MyRange
and do this at the start

Dim MyRange as Range

Set MyRange = Selection.Range.Duplicate

and at the end do a MyRange.Select


It's just a workaround


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Vivian Carroll reckoned:
Hi Steve, Here's the entire macro...

With Selection
.MoveRight Unit:=wdCharacter, Count:=1
With .Find
.ClearFormatting
.Text = "@"
.Forward = True
.Wrap = False
.Execute
End With
.Extend Character:="]"
End With


Vivian

Word Heretic said:
G'day "Vivian Carroll" <[email protected]>,

I'll need to see a code sample

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Vivian Carroll reckoned:

Thanks, but I forgot to mention that collapsing to the end has the same
result.

G'day "Vivian Carroll" <[email protected]>,

dont move to the right, collapse to the end

ensure you select the find result.


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Vivian Carroll reckoned:

In Word 2000 I have a macro in an Add-in template that finds the
next
@
symbol. It moves one character to the right before performing the
Find
in
case an @ symbol is currently selected.

The macro works correctly when run from the VBE or from a toolbar button.
However, when run from the Alt+2 shortcut, it does not move right before
performing the Find (so once it has found the first @, it stays on that @
each time Alt+2 is pressed). The weird thing is that if the template
itself
is opened, Alt+2 works correctly on text inserted into the
template -
it
just doesn't work in other documents.

What is the explanation for this and how can I make Alt+2 work correctly?

TIA,
Vivian Carroll
 

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