on 07-23-2014 7:10 PM
Hi All,
I'm trying to check if a print box exists in VBA, so the code can continue executing.
But I don't know how to check if the object exist and I get an error in VBA "control can't be found by id"
'...it goes to the print option
SessionSAP.findById("wnd[0]/usr/ctxt[8]").SetFocus
SessionSAP.findById("wnd[0]/usr/ctxt[8]").caretPosition = 0
SessionSAP.findById("wnd[0]/tbar[1]/btn[8]").press
'Print command
SessionSAP.findById("wnd[0]").sendVKey 86
'click on the SAP window box button to print
SessionSAP.findById("wnd[1]/tbar[0]/btn[0]").press
I the line of the code "click on the window box button" If the report does not contain data the box will never appear, there is where I get the error.
What I want to check is if the SAP print window is there or not, so the code can continue executing.
Hello Gabriel,
you can try this solution or if you know the title of the window, try this:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
If FindWindow(vbNullString, "Print ALV List") = 0 Then
MsgBox "The window does not exist."
Else
MsgBox "The window exists."
End If
Hope it works. Let us know the result.
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually the window is the same, regardless it has or not data. I don't know the name of the window, even if I knew it, It won't work the way I need.
I tried a workaround in a step back, testing IF a field contains some text, If the field says "report contains no data" the code will continue with the loop,
GGG = sessionSAP.findById("wnd[0]/usr/lbl[0,0]").Text
If Not GGG = "Report contains no data" Then
'some code, it won't execute if statement true
End if
Next
I haven't tried your link yet,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.