code executed inside the excel file (xlsm) work perfectly
Sub insertObject()
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("YourPath\Datasheet.xlsx")
objExcel.Application.Visible = True
objWorkbook.ActiveSheet.OLEObjects.Add(Filename:="YourPath\Placeholder.txt", _
Link:=False, DisplayAsIcon:=True, IconFileName:= _
"C:\Windows\system32\packager.dll", IconIndex:=0, IconLabel:= _
"C:\Placeholder.txt").Select
objWorkbook.SaveAs "yourPath\test.xlsx"
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
WScript.Quit
End Sub
this is the code i try to execute using vbs script
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("YourPath\Datasheet.xlsx")
objExcel.Application.Visible = True
ActiveSheet.OLEObjects.Add(Filename:="YourPath\Placeholder.txt", _
Link:=False, DisplayAsIcon:=True, IconFileName:= _
"C:\Windows\system32\packager.dll", IconIndex:=0, IconLabel:= _
"C:\Placeholder.txt").Select
objWorkbook.SaveAs "YourPath\test.xlsx"
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
WScript.Quit
i replace the paths with the real ones of course the code work perfectly inside the macro but failed inside vbs script when i try to run it using the cmd command.