Hello
Am using the below excel VB code to transfer the output from SAP to excel but am encountering an issue at the last step where SAP comes up with SAVE AS dialog box asks the destination/path to save the file. I need this step as a part of automation too......please help
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Macro2()
Dim Application, Connection, session As Object
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
Set Connection = Application.Children(0)
Set session = Connection.Children(0)
Dim AJ As Workbook
Set AJ = ActiveWorkbook
'''''SAP
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
AJ.Activate
Dim pern As Long
pern = 2
Range(Cells(pern, 1), Cells(pern, 1)).Select
While ActiveCell.Value <> ""
If ActiveCell.Value <> "" Then
Range(Cells(pern, 1), Cells(pern, 1)).Select
Selection.Copy
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nksbb"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/lbl[5,10]").SetFocus
session.findById("wnd[0]/usr/lbl[5,10]").caretPosition = 0
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/lbl[12,12]").SetFocus
session.findById("wnd[0]/usr/lbl[12,12]").caretPosition = 16
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/ctxtKOSTL-LOW").Text = Range(Cells(pern, 1), Cells(pern, 1))
session.findById("wnd[0]/usr/ctxtR_BUDAT-LOW").Text = "07/29/2013"
session.findById("wnd[0]/usr/ctxtR_BUDAT-HIGH").Text = "08/25/2013"
session.findById("wnd[0]/usr/ctxtP_DISVAR").Text = "/nd_cesumm"
session.findById("wnd[0]/usr/ctxtP_DISVAR").SetFocus
session.findById("wnd[0]/usr/ctxtP_DISVAR").caretPosition = 10
session.findById("wnd[0]/usr/btnBUT1").press
session.findById("wnd[1]/usr/txtKAEP_SETT-MAXSEL").Text = "999999999"
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").Select
session.findById("wnd[0]/tbar[1]/btn[43]").press
'session.findById("wnd[1]/usr/radRB_OTHERS").SetFocus
'session.findById("wnd[1]/usr/radRB_OTHERS").Select
'session.findById("wnd[1]/usr/cmbG_LISTBOX").key = "04"
'session.findById("wnd[1]/tbar[0]/btn[0]").press
Workbooks.Open Filename:="C:\Documents and Settings\sin21757\Desktop\export.XML"
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\sin21757\Desktop\SAP\" & Range("a3") & ".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
pern = pern + 1
End If
Range(Cells(pern, 1), Cells(pern, 1)).Select
Wend
End Sub
Bookmarks