For a few reasons discussed here I can't open an excel worksheet like this:
Set excel = CreateObject("Excel.Application")
excel.Visible = False
Set excelWb = excel.Workbooks.Open(file_path.xls)
So I'm trying to open it like this:
CreateObject("WScript.Shell").Run "excel.exe"
Wscript.Sleep 5000 ' wait for it to load
Set excel = GetObject(,"Excel.Application")
excel.visible = False
Set excelWb = excel.Workbooks.Open(file_path.xls)
However, this gives me this error:
ActiveX component can't create object
Unless I already have excel opened up, or I open up two pages like so:
CreateObject("WScript.Shell").Run "excel.exe"
Wscript.Sleep 5000
CreateObject("WScript.Shell").Run "excel.exe"
Wscript.Sleep 5000
Set excel = GetObject(,"Excel.Application")
excel.visible = False
Set excelWb = excel.Workbooks.Open(file_path.xls)
But this leaves me with one visible excel sheet. And it's sort of weird that I need to open up two in order to use GetObject
. Any ideas around this?
If your goal is to open the workbook in background, this may be a better option: