SendKeys Error Handling

Tarkin

New Member
Joined
Feb 12, 2019
Messages
12
I am trying to get Excel return an error message if a certain SendKeys command does not return the result I expect. In the case below, I expect an error as ALT + X will not give you any valid command (X does not appear in Excel when ALT is pressed). Ultimately, this is to test a presence of an Add-In the Excel Ribbon (which if it existed would have allowed the X key to proceed).


VBA Code:
Sub SendKeycheck()
On Error GoTo eh
Application.SendKeys ("%x")
Done:
MsgBox "All OK"
Exit Sub
eh:
MsgBox "The following error occurred: " & Err.Description
End Sub

But no luck! Any help would be appreciated!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
A keyboard shortcut that doesn't do anything is not an error, it will most likely be treated as 'nothing' and ignored the same as if you pressed the physical keys.

I got this by asking google how to check if an add in is installed.

 
Upvote 0
Thanks. The problem is that I do not have access to the name of the Add-in so it is not possible me to check this.
 
Upvote 0
Without the name of the add in to test, I don't see that there will be any reliable method that you could use.

I tried this on the theory that the {RIGHT} keystroke would move within the ribbon if Alt x was recognised, or move to another cell if it wasn't. It doesn't appear to be doing anything, but I might be missing something simple, sendkeys is not something I'm in the habit of using.
VBA Code:
tmp = ActiveCell.Address
Application.SendKeys ("%x")
Application.SendKeys ("{RIGHT}")
If ActiveCell.Address = tmp Then
    MsgBox "add-in found"
Else
    MsgBox "add-in not found"
End If
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,458
Members
448,899
Latest member
maplemeadows

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top