I have a vbs script inside an automation process.
This script runs an Excel Macro splitting an Excel into multiple files based on row number.
What happens is: the script creates some splitted files and then throws an error:
MacroSubSplit.vbs(20, 1) (null): L'oggetto invocato si è disconnesso dai client corrispondenti. that is "object invoked has disconnected from its clients"
The macro comes from this answer: How to split spreadsheet into multiple spreadsheets with set number of rows?
I have modified it to open a file f.
Public Sub Split_Auto(f As String)
Dim wb As Workbook
Dim ThisSheet As Worksheet
Dim NumOfColumns As Integer
Dim RangeToCopy As Range
Dim WorkbookCounter As Integer
Dim wbDst As Workbook
Dim RowsInFile
Dim Prefix As String
Application.ScreenUpdating = False
'Seleziona file
Dim fDialog As Office.FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
Set wbDst = Workbooks.Open(f)
'Initialize data
Set ThisSheet = wbDst.Worksheets("TotalData")
NumOfColumns = ThisSheet.UsedRange.Columns.Count
WorkbookCounter = 1
RowsInFile = 40000 'how many rows (incl. header) in new files?
Prefix = "Split" 'prefix of the file name
For p = 1 To ThisSheet.UsedRange.Rows.Count Step RowsInFile
Set wb = Workbooks.Add
'Paste the chunk of rows for this file
Set RangeToCopy = ThisSheet.Range(ThisSheet.Cells(p, 1), ThisSheet.Cells(p + RowsInFile - 1, NumOfColumns))
RangeToCopy.Copy wb.Sheets(1).Range("A1")
'Save the new workbook, and close it
strDate = Format(Now, "dd/MMM/yyyy")
wb.SaveAs ThisWorkbook.Path & "\" & Prefix & Format(Now, "yyyy-MM-dd") & "_SplitNum_" & WorkbookCounter
wb.Close
'Increment file counter
WorkbookCounter = WorkbookCounter + 1
Next p
Application.ScreenUpdating = True
Set wb = Nothing
End Sub
The macro is called from a vbs file
Option Explicit
if WScript.Arguments.Count = 0 then
WScript.Echo "Missing parameters"
WScript.Quit
end if
Dim xlApp, xlBook, File, objShell, input_path
File = WScript.Arguments.Item(0)
Set xlApp = CreateObject("Excel.Application")
set objShell = WScript.CreateObject ("WScript.Shell")
'WScript.Echo(objShell.CurrentDirectory)
input_path = objShell.CurrentDirectory & "\Input\" & File
'WScript.Echo("Input" & input_path)
'close without prompting
xlApp.DisplayAlerts = False
'~~> Change Path here
Set xlBook = xlApp.Workbooks.Open(objShell.CurrentDirectory&"\"&"Macro.xlsm", 0, True)
xlApp.Run "Foglio1.Split_Auto", CStr(input_path)
xlBook.Close False
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
'WScript.Echo "Finished."
WScript.Quit
Can you help me to find the solution to this problem?