Second part of macro doesn't work

L

Lucian Sitwell

The part of this macro with the SendKeys command doesn't work. If I switch
the order, then the SendKeys works, but then the spellcheck doesn't trigger.
i.e. only the first part of the macro works

Sub test2()

If Options.CheckGrammarWithSpelling = True Then
ActiveDocument.CheckGrammar
Else
ActiveDocument.CheckSpelling

End If

SendKeys "%3"
End Sub

Any help would be appreciated.

Lucian Sitwell
 
J

Jezebel

Hard to say without knowing what command you've assigned Alt-3 to. But as a
general proposition, using SendKeys is always fraught because -- as you've
found -- it depends on the context in which the keys are sent. It should
always be a last resort; within Word it is almost never needed: better and
more reliable simply to call the command itself.
 
L

Lucian Sitwell

The Alt-3 accesses a short cut in Reference manager, which has an add-in in
Word. The Alt-3 generates a bibliography for references in the document. I
don't know how to access the add-in directly. I can't look at the coding for
the add-in, since it is locked and protected.

LS
 
J

Jezebel

You should be able to find the command names either through the object
browser or through Intellisense. For the former, in VBA display the object
browser and select the add-in from the library list. Alternatively, add a
reference to the add-in to your VBA project, then try declaring a variable
using the reference as the source library -- see what objects you get, and
subsequently what methods and properties those objects have.
 
L

Lucian Sitwell

I alreadly tried that. The only objects that show up are under "This
Document".

RM9 (i.e. Reference Manager 9, the medical bibliography program) shows up in
the reference, but no commands listed.

LS
 
J

Jezebel

guess you're stuffed then



Lucian Sitwell said:
I alreadly tried that. The only objects that show up are under "This
Document".

RM9 (i.e. Reference Manager 9, the medical bibliography program) shows up
in
the reference, but no commands listed.

LS
 
T

Tony Jollans

When you do this via the UI do you press Alt+3 while the Spelling (or
Grammar) Dialog is open?
 
L

Lucian Sitwell

No. It does so sequentially. There might be a loss of focus. If I run the
macro step by step, the second part doesn't run. Furthermore, if I press
Alt-3 manually, it won't run unless I position the cursor in the Word
document and left-click. Then if I manually press Alt-3, it will run.

Lucian
 
T

Tony Jollans

I think the problem with your code is the same as with the UI. The focus is
in the wrong place.

The CheckSpelling or CheckGrammar leaves a dialog box open which you must
dismiss before you can sendkeys to the document window. Can you send Escape
first?

Beyond that I can't be much help because I don't know how context-sensitive
your Reference Manager AddIn is.
 

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