Por si a alguien le puede ser util, a continuacion pongo el codigo vba que he utilizado partiendo del script que cargaría a la pantalla de sap el numero de documento, la compañia y el año.
Private Sub Process_Download(NumDoc As String, Soc As String, Anno As String)
Dim filename As String
Session.findById(“wnd[0]/usr/txtRF05L-BELNR”).Text = NumDoc
Session.findById(“wnd[0]/usr/ctxtRF05L-BUKRS”).Text = Soc
Session.findById(“wnd[0]/usr/txtRF05L-GJAHR”).Text = Anno
Session.findById(“wnd[0]/usr/txtRF05L-GJAHR”).SetFocus
Session.findById(“wnd[0]/usr/txtRF05L-GJAHR”).caretPosition = 4
Session.findById(“wnd[0]”).sendVKey 0
Session.findById(“wnd[0]/titl/shellcont/shell”).pressContextButton "%GOS_TOOLBOX"
Session.findById(“wnd[0]/titl/shellcont/shell”).selectContextMenuItem "%GOS_VIEW_ATTA"
Session.findById(“wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell”).currentCellRow = 2
Session.findById(“wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell”).selectedRows = "2"
Session.findById(“wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell”).doubleClickCurrentCell
filename = NumDoc & “" & Soc & "” & Anno & ".pdf"
Esperar 3 ’ Funcion para hacer esperar al proceso 3 segundos.
AppActivate "Adobe Acrobat Reader DC"
Call AppActivate(“Adobe Acrobat Reader DC”)
Application.SendKeys “^+S”, True
Save_As Path & filename
Esperar 1
TerminateProcess "AcroRd32.exe"
Session.findById(“wnd[1]/tbar[0]/btn[12]”).press
Session.findById(“wnd[0]/tbar[0]/btn[3]”).press
End Sub
Private Sub Save_As(NomFil As String)
Dim hWnd As Long
Dim lang_code As Long
Dim Palabra As String
lang_code = Application.LanguageSettings.LanguageID(msoLanguageIDUI)
Select Case lang_code
Case 3081, 10249, 4105, 9225, 14345, 6153, 8201, 5129, 13321, 7177, 11273, 2057, 1033, 12297 ’ English
Palabra = “Save as"
Case 1034, 2058, 3082, 11274, 16394, 13322, 9226, 5130, 7178, 12298, 17418, 4106, 18442, 19466, 6154, 15370, 10250, 20490, 14346, 8202 ’ Español
Palabra = “Guardar como"
End Select
timeout = Now + TimeValue(“00:00:20”)
’* Automatic ‘Save as’ dialog from SAP => fillin SaveAsFileName and press ‘Save’ *
Do
hWnd = FindWindow(”#32770”, Palabra) 'Finding the save as window
DoEvents
Sleep 200
Loop Until hWnd <> 0 Or Now > timeout
If hWnd <> 0 Then
hWnd = FindWindowEx(hWnd, 0, “DUIViewWndClassName”, vbNullString) 'Find the child DUIViewWndClassName window
End If
If hWnd <> 0 Then
hWnd = FindWindowEx(hWnd, 0, “DirectUIHWND”, “”) 'Find the child DirectUIHWND window
End If
If hWnd <> 0 Then
hWnd = FindWindowEx(hWnd, 0, “FloatNotifySink”, “”) 'Find the child FloatNotifySink window
End If
If hWnd <> 0 Then
hWnd = FindWindowEx(hWnd, 0, “ComboBox”, “”) 'Child Combo Box
End If
If hWnd <> 0 Then
SetForegroundWindow (hWnd) 'Chilf Edit Window
Sleep 600
hWnd = FindWindowEx(hWnd, 0, “Edit”, “”) 'Child Combo Box
End If
If hWnd <> 0 Then
Application.SendKeys "{BACKSPACE}"
If Dir(NomFil) <> “” Then Kill NomFil
Application.SendKeys NomFil
Application.SendKeys "{ENTER}"
End If
End Sub
Sub TerminateProcess(ProcessName)
Dim WMIServ, Processes, Process
Set WMIServ = GetObject(“winmgmts:{impersonationLevel=” & “impersonate}!\.\root\cimv2”)
Set Processes = WMIServ.ExecQuery("Select * from Win32_Process " & _
“Where Name = '” & ProcessName & “’”)
For Each Process In Processes
Process.Terminate
Exit Sub
Next
End Sub
y estas son las llamadas a las librerias de windows:
Public Declare Function FindWindow Lib “user32” Alias “FindWindowA” _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib “user32” Alias “FindWindowExA” _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Public Declare Sub Sleep Lib “kernel32” (ByVal dwMilliseconds As Long)
Public Declare Function SetForegroundWindow Lib “user32” (ByVal hWnd As Long) As Long
Espero que sea de utilidad.