Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel macro execute command outside of excel

Status
Not open for further replies.

ryno525

MIS
Aug 1, 2005
3
0
0
US
Is it possible to use excel to input data into another application.

I want to use excel to input my Journal Entries into SAP.

All It needs to do is the eqivalent of me pressing:

Alt-tab, down arrow, down arrow, ctrl-V, Alt-Tab(back to excel).

Is this type of action possible with excel?
 
ryno525,
You can use the SendKeys method to send keystrokes to the active window, but I make no promises as to whether this will solve your problem.

The code below shows two different ways to send the keystrokes. The first method sends all five key combinations at once. The commented out statements (the single quote at beginning of a statement turns it into a non-executable comment) do it one key combination at a time. It is possible that one method will work better than the other. It is also possible that the code will work better without the ,TRUE as the second parameter.
Code:
Sub SendToSAP()
AppActivate "SAP"    ' Activate SAP. Change the text to match the title bar of the SAP window
'Alt-tab, down arrow, down arrow, ctrl-V, Alt-Tab(back to excel).
SendKeys "%{TAB}{DOWN 2}^V%{TAB}",TRUE
'SendKeys "%{TAB}",TRUE
'SendKeys "{DOWN}",TRUE
'SendKeys "{DOWN}",TRUE
'SendKeys "^V",TRUE
'SendKeys "%{TAB}",TRUE
End Sub
To install a sub in a regular module sheet:
1) ALT + F11 to open the VBA Editor
2) Use the Insert...Module menu item to create a blank module sheet
3) Paste the suggested code in this module sheet
4) ALT + F11 to return to the spreadsheet

To run a sub or macro:
5) ALT + F8 to open the macro window
6) Select the macro
7) Click the "Run" button

Optional steps to assign a shortcut key to your macro (which you'll want to do if the code is working for you):
8) Repeat steps 5 & 6, then press the "Options" button
9) Enter the character you want to use (Shift + character will have fewer conflicts with existing shortcuts)
10) Enter some descriptive text telling what the macro does in the "Description" field
11) Click the "OK" button

If the above procedure doesn't work, then you need to change your macro security setting. To do so, open the Tools...Macro...Security menu item. Choose Medium, then click OK.

Brad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top