Hi Guys,
I gathered SAP script together with VBA codes.
Basically, what problem I have.. when SAP script finishing own job, there is auto open of excel file.
I want to continue work on this open file, but VBA doesn't see this workbook and returns this error:
I have tried to rename file, I tried to open this workbook by commend related to path (but then i had error system has to re-open same workbook)..
Here is my VBA code, do you have some idea my experts how I could handle it in different way.. ?
I have heard that auto open excel file by some program in background may be not picked up by VBA code..
Here this step doesn't work.. -> Workbooks("GR_CHECK.XLSX").Activate
Thanks a lot !
I gathered SAP script together with VBA codes.
Basically, what problem I have.. when SAP script finishing own job, there is auto open of excel file.
I want to continue work on this open file, but VBA doesn't see this workbook and returns this error:
I have tried to rename file, I tried to open this workbook by commend related to path (but then i had error system has to re-open same workbook)..
Here is my VBA code, do you have some idea my experts how I could handle it in different way.. ?
I have heard that auto open excel file by some program in background may be not picked up by VBA code..
VBA Code:
Sub GR_Check()
If Not IsObject(SAPApp) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApp = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPApp.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
Dim todayDate As Date
Dim dateMinus7Days As Date
' Dzisiejsza data
todayDate = Date
' Dzisiejsza data -7 dni
dateMinus7Days = DateAdd("d", -7, todayDate)
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nZRLEI50040"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtP_BUKRS").Text = "C4B0"
session.findById("wnd[0]/usr/ctxtP_SNDPRN").Text = "ELSC4B0024"
session.findById("wnd[0]/usr/txtS_STATUS-LOW").Text = "51"
session.findById("wnd[0]/usr/ctxtS_CREDAT-LOW").Text = "2024-03-01"
session.findById("wnd[0]/usr/ctxtS_CREDAT-HIGH").Text = "2024-03-07"
session.findById("wnd[0]/usr/ctxtS_CREDAT-HIGH").SetFocus
session.findById("wnd[0]/usr/ctxtS_CREDAT-HIGH").caretPosition = 10
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/cntlCC_0100A/shellcont/shell").currentCellColumn = "DESCRP"
session.findById("wnd[0]/usr/cntlCC_0100A/shellcont/shell").selectedRows = "0"
session.findById("wnd[0]/usr/cntlCC_0100A/shellcont/shell").doubleClickCurrentCell
session.findById("wnd[0]/usr/cntlCC_0100B/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"
session.findById("wnd[0]/usr/cntlCC_0100B/shellcont/shell").selectContextMenuItem "&XXL"
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "C:\Users\a.forycki\Desktop\iDOC Tool\Logs"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "GR_CHECK.XLSX"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 13
session.findById("wnd[1]/tbar[0]/btn[11]").press
session.findById("wnd[0]/tbar[0]/btn[15]").press
Workbooks("GR_CHECK.XLSX").Activate
n = Worksheets("Sheet1").Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count - 1
Workbooks("iDOC TOOL.XLSM").Worksheets("Tool").Activate
Range("E5").Select
ActiveCell.FormulaR1C1 = n
End Sub
Here this step doesn't work.. -> Workbooks("GR_CHECK.XLSX").Activate
Thanks a lot !