Problem with SendKeys + active window

R

Roadie

Hi,

I want to get data from another application (SAP). I'm using VBA i
Excel to control SAP using the command SendKeys. My goal is to launc
SAP, log in, perform some actions and save the results in a dat.file.
have already completed the code for doing so and it works just fine.

However, my problem is that if, while running the macro, anothe
application (for example my ergonomic program, the company messenge
service or the screensaver) pops up, the macro sends the keys to th
wrong application.

Is there any way I can prevent such a situation? Or when it's no
possible to prevent, at least detect that it's gone wrong? Or is i
possible to activate the SAP window before every time Excel sends keys
Or does anyone have a better solution?

TIA,

Anne
 
R

Ron de Bruin

Hi Roadie

That's why I avoid SendKeys
Try to add this for every SendKeys line
Don't know if this work but you can try

AppActivate Application.Caption
 
J

Jake Marx

Hi Annet,
Is there any way I can prevent such a situation? Or when it's not
possible to prevent, at least detect that it's gone wrong? Or is it
possible to activate the SAP window before every time Excel sends
keys? Or does anyone have a better solution?

As Ron pointed out, SendKeys can be very unreliable. I'd suggest
programmatically controlling SAP if possible. It would undoubtedly be more
work, but it would be a more robust solution in the long term. Here's a
page on the SAP site that suggests that automation of SAP from an external
application is possible:

http://help.sap.com/saphelp_45b/helpdata/de/8c/20e2ab493311d1894a0000e829fbbd/frameset.htm

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
R

Roadie

Thanks for your reactions.

The AppActivate command could be an option, but I'm afraid that's stil
not fully safe.

I would like to make a macro that controls SAP and performs all th
actions, but I'm not sure how. I have done something similar wit
another application (Reflection), but that was much easier, becaus
Reflection had a recorder built in.
I can see in the menu that SAP has options like 'Report', 'Utilities'
'Jobs', so I guess SAP may have a recorder, but since I'm no
authorized to perform those transactions, that's not very helpful.
Getting authorization is probably a Mission Impossible, becaus
management believes that we should use SAP instead of Excel and the
won't support my attempts to get our IT-department to help me, althoug
I myself and my colleagues are convinced that Excel is a better too
for making Graphs etc.

I have a feeling I should use CreateObject and I think I need som
library, but I really can't find out where to find it. How can I fin
out what I need and where can I find it? Or should I use somethin
else? I have some knowledge of using ODBC, but in this case, that's no
an option. I know very little of DAO, OLE, ActiveX.
Can anyone help me? Or maybe give a hint as to what direction I shoul
go? Preferably with examples? Please???

TIA again,

Anne
 
J

Jake Marx

Hi Annet,

I'm not very familiar with SAP. I would suggest you do a google search on
"Automate" and "SAP" and "vb" to get more information. I did this and found
the following site, which has some more info:

http://www.sapgenie.com/interfaces/

It looks like there are quite a few third-party solutions that may work for
you. You may also want to post to an SAP newsgroup if you can find one....

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
Joined
Aug 2, 2013
Messages
2
Reaction score
0
Please could you tell me if you managed to send ENTER strokes
to SAP ?
I managed to send single data out of a c++ script to excell and SAP.
But adding the ENTER stroke to pass on next cells for following data,
only works with Excel , not SAP: only the first cell is filled with the first data, the other ones remain blank and the active cell remains the frist one.
Do you have any idea why ?
Thank you so much for your reply.
Charles.


Hi,

I want to get data from another application (SAP). I'm using VBA i
Excel to control SAP using the command SendKeys. My goal is to launc
SAP, log in, perform some actions and save the results in a dat.file.
have already completed the code for doing so and it works just fine.

However, my problem is that if, while running the macro, anothe
application (for example my ergonomic program, the company messenge
service or the screensaver) pops up, the macro sends the keys to th
wrong application.

Is there any way I can prevent such a situation? Or when it's no
possible to prevent, at least detect that it's gone wrong? Or is i
possible to activate the SAP window before every time Excel sends keys
Or does anyone have a better solution?

TIA,

Anne

--
 
Joined
Aug 2, 2013
Messages
2
Reaction score
0
Well sorry the first carriage return works but not the other ones.
Only the first cell is filled , the second cell is then activated by the first ENTER stroke
but the rest remains blank.
Once the last part of the supposed content of the last (3rd) cell was typed also in the second cell, that happend only once (??).
Thank you for your reply.

Please could you tell me if you managed to send ENTER strokes
to SAP ?
I managed to send single data out of a c++ script to excell and SAP.
But adding the ENTER stroke to pass on next cells for following data,
only works with Excel , not SAP: only the first cell is filled with the first data, the other ones remain blank and the active cell remains the frist one.
Do you have any idea why ?
Thank you so much for your reply.
Charles.


Hi,

I want to get data from another application (SAP). I'm using VBA i
Excel to control SAP using the command SendKeys. My goal is to launc
SAP, log in, perform some actions and save the results in a dat.file.
have already completed the code for doing so and it works just fine.

However, my problem is that if, while running the macro, anothe
application (for example my ergonomic program, the company messenge
service or the screensaver) pops up, the macro sends the keys to th
wrong application.

Is there any way I can prevent such a situation? Or when it's no
possible to prevent, at least detect that it's gone wrong? Or is i
possible to activate the SAP window before every time Excel sends keys
Or does anyone have a better solution?

TIA,

Anne

--
 

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