ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with SendKeys + active window (https://www.excelbanter.com/excel-programming/296059-problem-sendkeys-active-window.html)

Roadie

Problem with SendKeys + active window
 
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

--
Message posted from http://www.ExcelForum.com


Ron de Bruin

Problem with SendKeys + active window
 
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



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Roadie " wrote in message ...
Hi,

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

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

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?

TIA,

Annet


---
Message posted from http://www.ExcelForum.com/




Jake Marx[_3_]

Problem with SendKeys + active window
 
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/help...d/frameset.htm

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

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


Roadie[_2_]

Problem with SendKeys + active window
 
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

--
Message posted from http://www.ExcelForum.com


Jake Marx[_3_]

Problem with SendKeys + active window
 
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]


Thanks for your reactions.

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

I would like to make a macro that controls SAP and performs all the
actions, but I'm not sure how. I have done something similar with
another application (Reflection), but that was much easier, because
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 not
authorized to perform those transactions, that's not very helpful.
Getting authorization is probably a Mission Impossible, because
management believes that we should use SAP instead of Excel and they
won't support my attempts to get our IT-department to help me,
although I myself and my colleagues are convinced that Excel is a
better tool for making Graphs etc.

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

TIA again,

Annet


---
Message posted from http://www.ExcelForum.com/




All times are GMT +1. The time now is 05:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com