cancel
Showing results for 
Search instead for 
Did you mean: 

Save report to MHTML format using Gui script

Former Member
0 Kudos

hello all,

how can i save a report in .MHTML format using Gui Script. I am not able to record the "Save as" dialog box option with guiscripts. i am on ECC 6

thansk in adv.

Kris

Accepted Solutions (0)

Answers (4)

Answers (4)

0 Kudos

Hi @holger.khn holger.khn

Can you help me with this issue? I have the same problem, when my VBA Script runs into Excel.

When calls the instruction session.findById("wnd[0]/tbar[1]/btn[43]").press the macro stops in the "Save as " window. I just want to know what is the " nexts steps codes" to proceed to save the file in .MHTML format.

Do you have an alternative way to solve this? I've tried a lot and still not found a solution.

Thanks in advance .

0 Kudos

Hi Krishna,

uncheck the "Show native MS Windows dialogs" option in the SAPGUI options (see screenhot), then it will work.

All the best

Martin

Former Member
0 Kudos

Hi comunity ,

could you please help me with the same problem ?

Script below :

    If Not IsObject(sapplication) Then
    Set SapGuiAuto = GetObject("SAPGUI")
   Set sapplication = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(Connection) Then
    Set Connection = sapplication.Children(0)
     End If
     If Not IsObject(session) Then
    Set session = Connection.Children(0)
     End If
     If IsObject(WScript) Then
    WScript.Connection session, "on"
    WScript.Connection sapplication, "on"

End If

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

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

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

session.findById("wnd[0]/usr/ctxtMATNR-LOW").Text = ""

session.findById("wnd[0]/usr/ctxtWERKS-LOW").Text = "a709"

session.findById("wnd[0]/usr/ctxtLGORT-LOW").Text = "rp01"

session.findById("wnd[0]/usr/ctxtLGORT-HIGH").Text = "rp16"

session.findById("wnd[0]/usr/ctxtLGORT-LOW").SetFocus

session.findById("wnd[0]/usr/ctxtLGORT-LOW").caretPosition = 4

session.findById("wnd[0]/usr/btn%_LGORT_%_APP_%-VALU_PUSH").press

session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,0]").Text = "cher"

session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,0]").caretPosition = 4

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

session.findById("wnd[0]/usr/ctxtCHARG-LOW").Text = ""

session.findById("wnd[0]/usr/ctxtP_VARI").Text = "/ostatki"

session.findById("wnd[0]/usr/ctxtP_VARI").SetFocus

session.findById("wnd[0]/usr/ctxtP_VARI").caretPosition = 8

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

'this line is push button (ctrl+shift+F7)

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

and after that i see window - Save As.

Thank you.

holger_khn
Contributor

Hello Yuriy.

If you are able to convert your code into VBA (e.g. from Excel VBA) I can share an code where USER32.dll API is used for remote control of this 'Save As' Windows dialog. Let me know when you still have this requirement and you can use MS Office VBA (e.g. from Excel) to realize your script.

Br, Holger

script_man
Active Contributor
0 Kudos

Hi Kris,

In this forum have already answered similar questions:

or

Regards,

ScriptMan

Former Member
0 Kudos

thanks script man,

below is the script i created but the problem i am facing is that it is not updating to the folder specified in Path

it goes to default sapworking dir how to correct that.

Path = "E:\UpgradeEcc6\export.MHTML"

Set wshell = CreateObject("WScript.Shell")

wshell.Run """C:\Documents and Settings\5018\Desktop\Macros\save_as.vbs """ & Path

if Wscript.Arguments.count > 0 then

set fs = CreateObject("Scripting.FileSystemObject")

if fs.fileExists(WScript.arguments(0)) then

Set myfile = fs.GetFile(WScript.arguments(0))

myfile.Delete

end if

set Wshell = CreateObject("WScript.Shell")

Do

bWindowFound = Wshell.AppActivate("Save As")

WScript.Sleep 1000

Loop Until bWindowFound

Do

Wshell.appActivate "Save As"

Wshell.sendkeys WScript.arguments(0)

WScript.Sleep 400

Wshell.appActivate "Save As"

Wshell.sendkeys "%s"

WScript.Sleep 400

bWindowFound = Wshell.AppActivate("Save As")

WScript.Sleep 400

Loop Until not bWindowFound

end if

regards

Kris

script_man
Active Contributor
0 Kudos

Hi Kris,

I can see no errors in your script. But this must be called from another script, before the window "Save as" appears.

For example:


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

Path = "E:\UpgradeEcc6\export.MHTML"
Set wshell = CreateObject("WScript.Shell")
wshell.Run """C:\Documents and Settings\5018\Desktop\Macros\save_as.vbs """ & Path
...
session.findById("wnd[0]/usr/btn%_S_BNAME_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/tbar[0]/btn23").press 
session.findById("wnd[1]/tbar[0]/btn[8]").press
...

Regards,

ScriptMan

Former Member
0 Kudos

Hi Script Man,

I am having a similar issue to export to MHTML using SAP Scripting. I created a macro that open SAP GUI and do the required transaction. However, I got stuck exporting to MHTML. The code must save as MHTML in the path described below and then open the "export.MHTLM" file.

This is the code I have until now:

Sub SAPScripting_exportMHTML()

Set app = CreateObject("Sapgui.ScriptingCtrl.1")

Set Connection = app.OpenConnection("# E05 - R/3 - Produção", True)

Set Session = Connection.Children(0)


'Code to login on SAP GUI and do desired transaction:


Session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "C2MARCOSEC"

Session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "*******"

Session.findById("wnd[0]/usr/pwdRSYST-BCODE").SetFocus

Session.findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 8

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

Session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").selecedNode = "F00003"

Session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00003"

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

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

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

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

'This is where I try to export to MHTML:


Path = "D:\Users\est.marcosec\Desktop\Marcos\SAP - Script\export.MHTML"      'The "export.MHTML" file already exists

Set Wshell = CreateObject("WScript.Shell")

Wshell.Run """D:\Users\est.marcosec\Desktop\Marcos\SAP - Script\save_as.vbs """ & Path

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

End Sub

It would be great to get this code done. I send several reports everyday. This will save a lot of time.


Best Regards,


Marcos Eickhoff Cortopassi