Set objExcel = CreateObject("Excel.Application")

On this line, I am getting “The system cannot find the file specified”

I am trying to open excel, even more frustrating is that this used to work with excel, now it doesnt. Is it because i am on excel 2016 now?

4 Spice ups

What else goes with it, that is not enough info.

Also the usual disclaimer…

If you post code, please use the ‘Insert Code’ button. Please and thank you!

Full source:

'###################################################################
'##           Script to check the status of machines              ##
'##           Author: Unknown                  		          ##
'##           Date: 03-30-2012                       		  ##
'##           modified by: Vikas Sukhija                          ##
'###################################################################
'# call excel applicationin visible mode
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2

'# Define Labels 
objExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "Results"
 
'# Create file system object for reading the hosts from text file
Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("c:\Store\MachineList.Txt")
 
'# Loop thru the text file till the end 
Do While Not (InputFile.atEndOfStream)
HostName = InputFile.ReadLine
  
'# Create shell object for Pinging the host machines 
Set WshShell = WScript.CreateObject("WScript.Shell")
Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)
objExcel.Cells(intRow, 1).Value = HostName
 
'# use switch case for checking the machine updown status
Select Case Ping
Case 0 objExcel.Cells(intRow, 2).Value = "Up"
Case 1 objExcel.Cells(intRow, 2).Value = "Down"
End Select
intRow = intRow + 1
 
Loop

I did use the “insert code” on the OP, i dont know what happened

So… that looks like VB script… you posted in the PowerShell forum… :¬)

Correct. I couldn’t find a VB or scripting forum.

It’s been a long time (12+ years?) since I’ve launched Excel from VBScript, but digging through my old code I see that I’m applying a file type constant prior to launching. Pretty sure this does not fit your scenario. I tried running with the line present and missing and had no failures either way.

Const msoFileTypeExcelWorkbooks = 4
Set objExcel = CreateObject("Excel.Application")

I copied your first few lines of code and ran them on my machine without a problem. Windows 10 with Office 2010.

My suggestion: find a machine with an older version of Office and try it there.

How are you launching the script? Inside an IDE, from the command line, as a task, …?

$objExcel = new-object -comobject excel.application 

I tried this powershell command to start excel and it also doesnt work. here is the error:

new-object : Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed
due to the following error: 80070002 The system cannot find the file specified. (Exception from HRESULT: 0x80070002).
At line:1 char:1

  • new-object -comobject excel.application
  • CategoryInfo : NotSpecified: (:slight_smile: [New-Object], FileNotFoundException
  • FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.NewObjectCommand

So something isnt allowing excel to open from the COM object

fixed. excel had the wrong path in dcom

1 Spice up

How did you change the path? I am facing the same issue.

CD C:\Program Files (x86)\Microsoft Office\Office14

or whatever office you have

then do a

EXCEL.EXE –REGSERVER

reboot after and see if that helps. let me know if it doesnt