on 07-25-2013 3:38 PM
Hi Evgeniy - I am using this approach for quite some time now where I run 2 vb scripts - one is the main program, other is the data load program. I use it to bring data from a data file into SAP using the WIndows explorer panel "Open". This might not be exactly what you are looking for but a variation of the approach might work for you.
on Main:
FileName = "C:\PV.txt" '<--- provide input filename
Wshell.run "c:\tmp\DataLoad.vbs " & FileName,1,False '<---- run the other vbs program to wait for the proper WIndows (Open) panel to appear
session.findById("wnd[0]/usr/btn%_QMNUM_%_APP_%-VALU_PUSH").press '<-- pressing the button that will trigger the (Open) panel. once opened, the Dataload.vbs will drop contents into the filename
session.findById("wnd[1]/tbar[0]/btn[23]").press '<--- then switch back to the main program to accept the loaded bvalues from the input file
the DataLoad.vbs program:
Dim FileNam2
Set Wshell = CreateObject("WScript.Shell")
Do
bWindowFound = Wshell.AppActivate("Open")
WScript.Sleep 1000
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Open")
if (bWindowFound) Then
Wshell.appActivate "Open"
WScript.Sleep 100
Wshell.sendkeys "{TAB}"
Wshell.sendkeys "{TAB}"
Wshell.sendkeys "{TAB}"
Wshell.sendkeys "{TAB}"
Wshell.sendkeys "{TAB}" 'make 4 or 5 depeneding on the platform 4:XP, 5:Win7
WScript.Sleep 100
FileNam2 = WScript.Arguments.Item(0)
Wshell.sendkeys FileNam2
WScript.Sleep 100
Wshell.sendkeys "{ENTER}"
WScript.Sleep 100
end if
--------------------------------------------------------
This works in dropping filename into a Windows explorer panel. Hope it helps.
Regards
Umur
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Umur,
your example VERY & VERY & VERY helpful!
basis on this i'm created macro for my .
This combination working as expected.
Thanks!
i'm run it from VBA(Excel)
Sub ttest()
Set Wshell = CreateObject("WScript.Shell")
patch = Cells(1, 2).Value '"c:\Users\kvitnitskiy.e\Desktop\DataSaveAs.vbs"
Wshell.Run patch
If Not IsObject(sap) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set sap = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = sap.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 sap, "on"
End If
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nzc90"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/usr/txtENAME-LOW").SetFocus
session.findById("wnd[1]/usr/txtENAME-LOW").caretPosition = 6
session.findById("wnd[1]/usr/txtENAME-LOW").Text = "aq8017"
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").currentCellRow = 1
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "1"
session.findById("wnd[1]/tbar[0]/btn[2]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
End Sub
and vbs file
Dim FileName
Set Wshell = CreateObject("WScript.Shell")
Do
bWindowFound = Wshell.AppActivate("Save As")
WScript.Sleep 1000
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Save As")
If (bWindowFound) Then
Wshell.AppActivate "Save As"
'WScript.Sleep 100
Wshell.SendKeys "{TAB}"
Wshell.SendKeys "{TAB}"
Wshell.SendKeys "{TAB}"
Wshell.SendKeys "{TAB}"
Wshell.SendKeys "{TAB}"
'WScript.Sleep 100
tdata = Replace(Now, ":", "_")
FileName = "c:\Users\kvitnitskiy.e\Desktop\"&tdata &".txt"
Wshell.SendKeys FileName
WScript.Sleep 100
Wshell.SendKeys "{ENTER}"
'WScript.Sleep 100
Wshell.SendKeys "{TAB}"
'WScript.Sleep 100
Wshell.SendKeys "{ENTER}"
End If
Hi Huang - you don't have to have VBA to make this work. It all depends how you are building your app. In the example I used, it is strictly using the VBS approach.. I am running the main script in vbs and the load script also in vbs. This does not incorporate an Excel linkage but like in Evgeniy's case, looks like he is incorporating an Excel hook as well.
Regards
Umur
Hello Evgeniy,
I have tried it with transaction code SE80 and download a source, to get the same dialog as you. SAP GUI Scripting records the activities of this dialog in my case ditto not.
So I try different ways like this
session.findById("wnd[0]/mbar/menu[3]/menu[10]/menu[4]/menu[1]").select
Set wsh = CreateObject("WScript.Shell")
wsh.SendKeys "Test.abap{ENTER}"
and this
session.findById("wnd[0]/mbar/menu[3]/menu[10]/menu[4]/menu[1]").select
Set autoit = CreateObject("AutoItX3.Control")
autoit.Sleep 500
autoit.WinActivate "Speichern unter", ""
autoit.Send "Test.abap{ENTER}"
to fill the dialog, but without success.
If you find a stable solution, let us know. It is an interesting problem.
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.