Sending commands to another non Office/Microsoft application using VBA in Excel 2007

JonnnyExcel

New Member
Joined
Feb 9, 2011
Messages
8
Thank you for the great forum to ask questions and get answers. I have used it many times to help out with Excel problems.
I am trying to write VBA code in Excel 2007 to open (I have that part figured out) and then access the Tools menu, enter and start a data acquisition by “clicking” the Execute button of a non Office/Microsoft program that is collecting data from a sensor controller. The program responds to short cut keys (Alt+T, enter and then Alt+E). I have tried using SendKeys, also understand that this is not a robust way to do this, and can’t get it to work. Below is some of the code I have tried.
Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]'Access Tools Menu[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Application.SendKeys "{%}t"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]' delay 1 sec[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Application.Wait Now + TimeValue("00:00:01")[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]'Enter[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Application.SendKeys "{~}"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]'delay 5 sec to allow program to respond[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Application.Wait Now + TimeValue("00:00:05")[/COLOR][/SIZE][/FONT]
I have tried in place of Application SendKeys declaring for example AltKey As String and then using SendKeys AltKey. I believe that it maybe a problem of focus, the program is not the focus so the code doesn’t know where to send the “keys” to. I can’t figure out how to make the focus this non Office program. :confused:
Any and all help would be much appreciated. I will need this to be robust as it will be on our manufacturing floor in use with people who don’t really understand computers that well.
Thank you and looking forward to your help.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I have figured this out. The issue was focus on the non Office program. I couldn't figure out how to change the focus to that program, got errors on different ways to change the focus. i solved it doing this:

Code:
Dim OpenPro
OpenPro = Shell("C:\Program Files\xyz_program.exe", 1)

This makes the program in focus when started. I am now onto my next challenge of how to change the focus back to this program and close when the Excel file is closed.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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