Skip to Content
avatar image
Former Member

Pasting filename in a panel using script

Hi Experts - I ran into a problem when trying to feed a filename into an open file dialog. I used this approach in the past with an "Open" dialog and thought same would work for "Import file" dialog box.

My main script is below:

If Not IsObject(application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

Set connection = application.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 application, "on"

End If

session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").text = "/niw32"

session.findById("wnd[0]").sendVKey 0

OrdNum = "7237602"

set Wshell = CreateObject("WScript.Shell")

session.findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").text = OrdNum

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_PCATTA_CREA"

'>>> these 2 lines above bring up the dialog box <<<<<

Wshell.run "c:\tmp\Scandf.vbs",1,False

'>> after the filename is dropped in the dialog box by the Scandf.vbs script it should continue with the process <<

session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/subSUB_KOPF:SAPLCOIH:1102/btn%#AUTOTEXT001").press

session.findById("wnd[1]/usr/sub:SAPLBSVA:0201[1]/chkJ_STMAINT-ANWSO[0,0]").selected = true

session.findById("wnd[1]/usr/sub:SAPLBSVA:0201[1]/chkJ_STMAINT-ANWSO[0,0]").setFocus

session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[0]/tbar[0]/btn[11]").press

I am calling a script called Scandf.vbs where I have the filename I want to drop into the dialog box. This is the Scandf.vbs:

If Not IsObject(application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

Set connection = application.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 application, "on"

End If

set Wshell = CreateObject("WScript.Shell")

MsgBox "in sub"

Do

bWindowFound = Wshell.AppActivate("Import file")

WScript.Sleep 1000

Loop Until bWindowFound

bWindowFound = Wshell.AppActivate("Import file")

if (bWindowFound) Then

Wshell.appActivate "Import file"

WScript.Sleep 100

Wshell.sendkeys "c:\EQ2814.txt"

WScript.Sleep 100

Wshell.sendkeys ""

end if

EQ2814.txt is the filename I want to drop in.

THe cursor is in the filename field and waiting for input. It just sits there after the dialog box is called and does not drop in the filename.

Can anybody see what I am doing wrong?

Thanks

Umur

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 05, 2010 at 07:54 AM

    Hi Umur,

    Unfortunately I do not have access to the transaction iw32. But you could try the following.

    In the main script should be called Scandf.vbs previously:

    . . .
    set Wshell = CreateObject("WScript.Shell")
    Wshell.run "c:\tmp\Scandf.vbs",1,False
    session.findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").text = OrdNum
    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_PCATTA_CREA"
    . . .
    

    Scandf.vbs does not need the first 14 rows:

    set Wshell = CreateObject("WScript.Shell")
    MsgBox "in sub"
    Do 
    bWindowFound = Wshell.AppActivate("Import file") 
    WScript.Sleep 1000
    Loop Until bWindowFound
    '-> new
    Msgbox "Window = 'Import file' found"
    bWindowFound = Wshell.AppActivate("Import file")
    if (bWindowFound) Then
    Wshell.appActivate "Import file"
    WScript.Sleep 100
    Wshell.sendkeys "c:\EQ2814.txt"
    WScript.Sleep 100
    Wshell.sendkeys "{ENTER}"
    '-> new
    WScript.Sleep 100
    end if
    

    Otherwise one would have to examine the same level as the windows. For example:

    "Import file" # "Import file"

    Between the words Import and file are 2 spaces right.

    Regards,

    ScriptMan

    Edited by: ScriptMan on Oct 5, 2010 9:57 AM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Having the same problem too. I have the filepath inside my excel sheet. I got everything up and running (validations, loop, etc..) I just can't figure out how to do a code that will copy the path from my excel sheet, then paste it in the dialogbox in SAP đŸ˜”

      Public Sub AttachNow()

      doc = ActiveCell.Value

      attachment = ActiveCell.Offset(0, 1).Value 'this is the cell value where the filepath is copied

      salesorg = Range("F3").Value

       

          Dim current As Workbook

          Set current = ActiveWorkbook

          Dim ARlayout As String

          Dim objExcel

          Dim objSheet, intRow, i

          Set objExcel = GetObject(, "Excel.Application")

          Set objBook = objExcel.ActiveWorkbook

         

      Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object

      Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI

      Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected

      Set session = SAPCon.Children(0) 'Get the first session (window) on that connection

         

      'Start the transaction to access FB03

         

      session.findById("wnd[0]").resizeWorkingPane 235, 41, False

      session.findById("wnd[0]/tbar[0]/okcd").Text = "/nFB03"

      session.findById("wnd[0]").sendVKey 0

      session.findById("wnd[0]/usr/txtRF05L-BELNR").Text = doc

      session.findById("wnd[0]/usr/ctxtRF05L-BUKRS").Text = salesorg

      session.findById("wnd[0]/usr/ctxtRF05L-BUKRS").SetFocus

      session.findById("wnd[0]/usr/ctxtRF05L-BUKRS").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_PCATTA_CREA"

      'put code to paste path in dialog box here

      session.findById("wnd[0]/tbar[0]/okcd").Text = "/n"

      End Sub

      hello @Script Man, I hope you can help me with this dilemma đŸ˜”

  • Oct 04, 2010 at 05:36 PM

    Hi Umur,

    Sendkeys is a Method to Send KeyCombinations like Enter, or The F-Keys to the Active Application

    like in SAP the session.findById("wnd[0]").sendvKey 0

    You can't "Cpoy - Paste" Complete Text by sendkeys đŸ˜‰

    Perhaps you should try to split up your Text

    dummy = "EQ1234.txt"
    for i = 1 to len (dummy)
    wShell.Sendkeys{mid(dummy(1,i,1))
    next
    

    Greetings

    Thomas

    Edited by: Thomas Br on Oct 4, 2010 7:40 PM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      For those inquisitive minds out there, I confirmed that when it processes this step:

      session.findById("wnd[0]/shellcont/shell").selectContextMenuItem "PCATTA_CREA"

      and brings up the file import dialog box, that is where it hangs. It is almost like all processing of the script is halted until user clicks Open or Cancel on the dialog box screen. Won't go to the next line of the script.

      Wondering if anybody had this issue or is it unique to attaching a file to a work order through "Services for Object" functionality.

      Regards

      Umur

  • avatar image
    Former Member
    May 10, 2016 at 04:16 PM

    Hi,

    can we run Scandf.vbs, inside of the main script like function or Sub file?

    thank you.

    Add comment
    10|10000 characters needed characters exceeded