Я попробовал следующий код, чтобы напечатать документ в pdf. Control + P были нажаты в окне VBA, а не в окне SAP, как я хочу.
Option Explicit
Public SapGui, App, Connection, Session, SapGuiAuto, wshell, wscript, bWindowFound
Sub SAP()
If Not IsObject(App) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set App = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = App.Children(0)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
If IsObject(wscript) Then
wscript.ConnectObject Session, "on"
wscript.ConnectObject App, "on"
End If
Set wshell = CreateObject("WScript.Shell")
Do
bWindowFound = wshell.AppActivate("PDF Preview")
Loop Until bWindowFound
bWindowFound = wshell.AppActivate("PDF Preview")
'MsgBox ("window found")
wshell.SendKeys "{CAPSLOCK}"
MsgBox ("ddd")
bWindowFound = wshell.AppActivate("PDF Preview")
wshell.SendKeys "^(p)"
End Sub