Skip to Content
author's profile photo Former Member
Former Member

Checking an object exist in SAP

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jul 23, 2014 at 10:45 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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,

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.