Word FAQ problem (Bill Coan author)

J

Jean-Guy Marcil

G

Greg Maxey

JGM,

Sorry.

Excel is "not" open when I run the code.

The error occurs on the line:
Set oWB = oXL.Workbooks.Open(FileName:=WorkbookToWorkOn)

I know now why the error is thrown.

For some reason the following code is not throwing an error as the code
indicates it should if Excel is "not" already opened:

'If Excel is running, get a handle on it; otherwise start a new
instance of Excel
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
If Err Then
ExcelWasNotRunning = True
Set oXL = New Excel.Application
End If
 
J

Jean-Guy Marcil

Greg Maxey was telling us:
Greg Maxey nous racontait que :
JGM,

Sorry.

Excel is "not" open when I run the code.

The error occurs on the line:
Set oWB = oXL.Workbooks.Open(FileName:=WorkbookToWorkOn)

Have you tried adding the line
oXL.Visible = True
just before the "Set oWB..." line just to make sure that the application was
indeed created properly?
I know now why the error is thrown.

For some reason the following code is not throwing an error as the
code indicates it should if Excel is "not" already opened:

You mean that "If Err" is False when there are no Excel application running?
Are you sure you do not have an invisible application running (Sometimes an
Office application is not present in the Applications tab of the Windows
Task Manager, but is actually present in the Processes tab).
'If Excel is running, get a handle on it; otherwise start a new
instance of Excel
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
If Err Then
ExcelWasNotRunning = True
Set oXL = New Excel.Application
End If

I ran the code as is form the web site (Just changed the path/name of the
Excel file) and it ran without any problems, even when Excel was not
previously running.

Then, as a test. I used a wrong path, and the error was caught as it was
supposed to.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

Greg Maxey

Hi JGM


"Are you sure you do not have an invisible application running
(Sometimes an
Office application is not present in the Applications tab of the
Windows Task Manager, but is actually present in the Processes tab)."

Knowledge is a wonderful thing isnt' it ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top