on 02-15-2024 2:10 PM
Hello! I need to save the generated pdf from SAP. My code is doing everything until this moment - then SAP is "giving back" the role to Windows and I cannot do anything (via VBA) with this window
Can someone help me?
Hello @aleksandra-0601
try this to handle native Windows Dialogs:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" ( _
ByVal hwnd As Long) As Long
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "Descarga de archivos")
SetForegroundWindow hwnd
SendKeys %(b)
At first it is necessary to be sure that the dialog window is in foreground. Here we use two Windows API functions, FindWindow and SetForegroundWindow. Now it is possible to use the SendKeys statement with which you can send one or more keystrokes to the active window. In the example above %(b) means Alt is pressing with b to save the document.
Best regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @stefan_schnell, many thanks for answering my question! I think we are almost there, but there is a problem with sendkeys command, VBA considers % as invalid character - compile error
It is the same if I use { }
Hello @stefan_schnell, I tried this combination as well. It wont generate the error, but doesn`t save the file. I think the code till this line works fine, because the window seems to be active, but the biggest obstacle is to move it further with any action. I also tried with sendkeys b and tab, to watch if it opens/changes but it didn`t. So I think something is wrong with sendkeys method
Hello @aleksandra-0601,
I tried it and in my case it works without any problems, here my approach.
At first I execute in one thread the following code:
Sub Test()
Dim result
result = MsgBox( _
"Desea abrir o guardar este archivo?", _
vbAbortRetryIgnore + vbInformation + vbApplicationModal, _
"Descarga de archivos" _
)
Debug.Print result
End Sub
This code opens the following dialog:
Then I use the described approach in another thread:
And it works as expected:
3 = vbAbort = Abbruch
Maybe you should just try an additional Sleep.
Best regards
Stefan
User | Count |
---|---|
64 | |
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.