Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3167

Calling a script from another script

$
0
0

Dear community,

 

I am trying to implement the solution given by Script Man in this discussion (http://scn.sap.com/message/9593362). For this, I have 2 files, both located in the folder C:\Users\u32q\Desktop.

 

Main script.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

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

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

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

OrdNum = "2013584402"

set Wshell = CreateObject("WScript.Shell")

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

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

Wshell.run "C:\Users\u32q\Desktop\SecondFile.vbs",1,False

session.findById("wnd[0]/titl/shellcont/shell").pressButton "%GOS_TOOLBOX"

session.findById("wnd[0]/shellcont/shell").pressContextButton "CREATE_ATTA"

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

 

SecondFile.vbs:

 

Sub SecondFile

Set Wshell = CreateObject("WScript.Shell")

MsgBox "in sub"

Do

    bWindowFound = Wshell.AppActivate("Importar file")

    ' WScript.Sleep 1000

    wshell.run "C:\Users\u32q\Desktop\sleep_1000.vbs",1,true

Loop Until bWindowFound

Msgbox "Window = 'Import file' found"

bWindowFound = Wshell.AppActivate("Import file")

if (bWindowFound) Then

    Wshell.appActivate "Import file"

    ' WScript.Sleep 100

    wshell.run "C:\Users\u32q\Desktop\sleep_100.vbs",1,true

    Wshell.sendkeys "C:\Users\u32q\Desktop\teste anexo ordem.txt"

    ' WScript.Sleep 100

    wshell.run "C:\Users\u32q\Desktop\sleep_100.vbs",1,true

    Wshell.sendkeys "{ENTER}"

    ' WScript.Sleep 100

    wshell.run "C:\Users\u32q\Desktop\sleep_100.vbs",1,true

end If

End sub

 

I have executed the main script from both SAP and explorer, but it does not causes the second script to be executed. In fact, I never got the msgbox "in sub".

 

Am I missing something? Does anyone know what I am doing wrong?

 

Also, is it possible to implement this solution in vba code, so It can be executed from excel?

 

Any help would be much appreciated.


Viewing all articles
Browse latest Browse all 3167

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>