cancel
Showing results for 
Search instead for 
Did you mean: 

Save roport as file via Windows explorer

Former Member
0 Kudos

Dear comunity,

does any boby know, how can i save report  report ZC90 via Win Explorer.

i'm tried to record macro by SAP macro recorder but unsucessfull.

only one row recordered

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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.Sleep1000
LoopUntil bWindowFound
bWindowFound = Wshell.AppActivate("Open") 
if (bWindowFound) Then
Wshell.appActivate"Open"
WScript.Sleep100
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.Sleep100
FileNam2 = WScript.Arguments.Item(0)  
Wshell.sendkeys FileNam2
WScript.Sleep100
Wshell.sendkeys"{ENTER}"
WScript.Sleep100
endif     

--------------------------------------------------------

This works in dropping filename into a Windows explorer panel. Hope it helps.

Regards
Umur

stefan_schnell
Active Contributor
0 Kudos

Hello Umur,

cool idea

Cheers

Stefan

Former Member
0 Kudos

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

Former Member
0 Kudos

Glad it helped you, Evgeniy. The credit mostly belongs to ScriptMan who offered the approach. I just made it work for my particular case.

Regards

Umur

script_man
Active Contributor
0 Kudos

Hi Umur,

who would have thought that this construction is still interesting? 

Regards,

ScriptMan

Former Member
0 Kudos

Is it worked, I don't have authorization of T-code ZC90, so I can't run this in my computer.

Is it means you need both excel VBA and VBS file so it can fulfill your requirement?

Former Member
0 Kudos

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

Answers (1)

Answers (1)

stefan_schnell
Active Contributor
0 Kudos

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