I'm running a script that extracts from SAP a number of N archives(based on a input file that contains the name of each file). The scripts reads the data for each file from a input txt file and writes the status after each run to an Excel file.
After each run the file is generated but before being saved it gives this error.
Windows cannot find 'filename.zip'. Make sure you typed the name correctly and then try again
I have disabled the Read Only option of the folder where I'm saving the report, I've run sfc /scannow
in case I have any corrupted files in my system and I have also checked the Path variables in case any were missing but to no avail.
Here is the code
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
Set filesysobj = CreateObject("Scripting.FileSystemObject")
Set list = CreateObject("Scripting.Dictionary")
Set file = filesysobj.OpenTextFile("fullpath\to\input\file\.txt", 1)
' wb - workbook(the file), ws-worksheet(the first sheet of the excel file)
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("fullpath\to\excel\output\file")
objExcel.Visible = False
Set sheet = objWorkbook.sheets("Sheet1")
' Reading from the input file
nr = 0
Do until file.AtEndOfStream
request = file.ReadLine
list.Add nr, request
nr = nr + 1
Loop
file.Close
' Indexes for the lines and rows in the excel file
i = 2 ' Second Row
j = 5
For Each line in list.Items
On Error Resume Next
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "controlpanel\path"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[2]").press
' line - name from file
session.findById("wnd[0]/usr/ctxtZQT1D-REQ").text = line
session.findById("wnd[0]/usr/ctxtZQT1D-REQ").caretPosition = 9
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/tabsREQUEST_OBJECTS/tabpREQUEST_OBJECTS_FC6/ssubREQUEST_OBJECTS_SCA:/SYMSOFT/CP_ZQTMS010_NEW:0917/cntlCONTAINER/shellcont/shell").currentCellColumn = "DATE"
session.findById("wnd[0]/usr/tabsREQUEST_OBJECTS/tabpREQUEST_OBJECTS_FC6/ssubREQUEST_OBJECTS_SCA:/SYMSOFT/CP_ZQTMS010_NEW:0917/cntlCONTAINER/shellcont/shell").selectedRows = "0"
session.findById("wnd[0]/usr/tabsREQUEST_OBJECTS/tabpREQUEST_OBJECTS_FC6/ssubREQUEST_OBJECTS_SCA:/SYMSOFT/CP_ZQTMS010_NEW:0917/cntlCONTAINER/shellcont/shell").pressToolbarButton "ATT_DISP"
' define of the output path for the file & the filename
session.findById("wnd[1]/usr/ctxtDY_PATH").text = "fullpath\saving\folder"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = line & ".zip"
session.findById("wnd[1]/usr/ctxtDY_PATH").setFocus
session.findById("wnd[1]/usr/ctxtDY_PATH").caretPosition = 26
session.findById("wnd[1]/tbar[0]/btn[0]").press
' -------Writing the errors
' End If
If Err.Number <> 0 Then
sheet.Cells(i, j).Value = "Error " & Err.Description
i = i + 1
Else
sheet.Cells(i, j - 1) = line
sheet.Cells(i, j) = "has been completed"
i = i + 1
End If
next
objExcel.ActiveWorkbook.Save
objExcel.Quit
The archives are saved correctly but without clicking OK on the error the script won't get past 1 iteration nor it will save the archive.