Hi All,
I am new to VBScript and need to format an Excel sheet using it. I found the following code online, but when I try to execute it, I encounter the error:
runmacro.vbs(17, 39) Microsoft VBScript compilation error: Expected statement
I am attempting to add a new cell at G1 and shift all the cells to the right with the code below. Could you please help me resolve this issue? If any additional details are needed, please let me know. Thanks in advance.
Thanks
I am new to VBScript and need to format an Excel sheet using it. I found the following code online, but when I try to execute it, I encounter the error:
Quote:
runmacro.vbs(17, 39) Microsoft VBScript compilation error: Expected statement
Code:
' VBScript to insert a cell and shift cells to the right
Dim objExcel, objWorkbook, objWorksheet
Dim strFilePath
' Get the Excel file path from the command line argument
strFilePath = WScript.Arguments(0)
' Create an Excel application object
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
' Open the Excel file
Set objWorkbook = objExcel.Workbooks.Open(strFilePath)
Set objWorksheet = objWorkbook.Sheets(1) ' Modify if you need a different sheet
' Insert a cell at G1 and shift cells to the right
objWorksheet.Range("G1").Insert Shift:=1 ' xlToRight
' Save and close the workbook
objWorkbook.Save
objWorkbook.Close
' Quit Excel application
objExcel.Quit
' Clean up
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing