Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Checking for existence of excel

Wouldn't the safest method of checking for excel is to really check to see if
it's there.

Both of these worked ok for me in MSWord--I'm not sure what language you're
using.

Option Explicit
Sub testme()
Dim myXL As Object

Set myXL = Nothing
On Error Resume Next
Set myXL = CreateObject("excel.application")
On Error GoTo 0

If myXL Is Nothing Then
'not installed
Else
myXL.Quit
End If

Set myXL = Nothing

End Sub

Sub testme2()
Dim myXL As Object
Dim isInstalled As Boolean

Set myXL = Nothing
On Error Resume Next
Set myXL = CreateObject("excel.application")
isInstalled = CBool(Err.Number = 0)
On Error GoTo 0

If isInstalled Then
myXL.Quit
Else
'not installed
End If

Set myXL = Nothing

End Sub

Mark wrote:

Hi,

My program needs to check if excel is installed before continuing so that way it doesn't fail if it can't use the Excel.Application object. Does anyone know a relaible way to check for this among all versions of Excel? I can't seem to find a steady registry key or file location that I know will always be there for any version. Thanks.

Mark


--

Dave Peterson

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Checking for existence of excel

Dave:

your method is safe but slow...
(just imagine your user has 10 addins installed)


it might be a bit faster to change as follows:
(it doesn't start a 2nd instance if there's already one running).

for this quick & dirty demo i've left out the disableevents and
displayalerts, which i normally would include.

on error resume next
set xlapp = GetObject(,"excel.application")
if not xlapp is nothing then
installed=true
else
set xlapp = CreateObject("excel.application")
if not xlapp is nothing then
xlapp.quit
installed=true
endif
endif
set xlapp=nothing



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


Dave Peterson wrote:

Wouldn't the safest method of checking for excel is to really check to
see if it's there.

Both of these worked ok for me in MSWord--I'm not sure what language
you're using.

Option Explicit
Sub testme()
Dim myXL As Object

Set myXL = Nothing
On Error Resume Next
Set myXL = CreateObject("excel.application")
On Error GoTo 0

If myXL Is Nothing Then
'not installed
Else
myXL.Quit
End If

Set myXL = Nothing

End Sub

Sub testme2()
Dim myXL As Object
Dim isInstalled As Boolean

Set myXL = Nothing
On Error Resume Next
Set myXL = CreateObject("excel.application")
isInstalled = CBool(Err.Number = 0)
On Error GoTo 0

If isInstalled Then
myXL.Quit
Else
'not installed
End If

Set myXL = Nothing

End Sub

Mark wrote:

Hi,

My program needs to check if excel is installed before continuing so
that way it doesn't fail if it can't use the Excel.Application
object. Does anyone know a relaible way to check for this among all
versions of Excel? I can't seem to find a steady registry key or
file location that I know will always be there for any version.
Thanks.

Mark



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Checking for existence of excel

None of my addins were loaded when I started excel this way.



keepITcool wrote:

Dave:

your method is safe but slow...
(just imagine your user has 10 addins installed)

it might be a bit faster to change as follows:
(it doesn't start a 2nd instance if there's already one running).

for this quick & dirty demo i've left out the disableevents and
displayalerts, which i normally would include.

on error resume next
set xlapp = GetObject(,"excel.application")
if not xlapp is nothing then
installed=true
else
set xlapp = CreateObject("excel.application")
if not xlapp is nothing then
xlapp.quit
installed=true
endif
endif
set xlapp=nothing



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool

Dave Peterson wrote:

Wouldn't the safest method of checking for excel is to really check to
see if it's there.

Both of these worked ok for me in MSWord--I'm not sure what language
you're using.

Option Explicit
Sub testme()
Dim myXL As Object

Set myXL = Nothing
On Error Resume Next
Set myXL = CreateObject("excel.application")
On Error GoTo 0

If myXL Is Nothing Then
'not installed
Else
myXL.Quit
End If

Set myXL = Nothing

End Sub

Sub testme2()
Dim myXL As Object
Dim isInstalled As Boolean

Set myXL = Nothing
On Error Resume Next
Set myXL = CreateObject("excel.application")
isInstalled = CBool(Err.Number = 0)
On Error GoTo 0

If isInstalled Then
myXL.Quit
Else
'not installed
End If

Set myXL = Nothing

End Sub

Mark wrote:

Hi,

My program needs to check if excel is installed before continuing so
that way it doesn't fail if it can't use the Excel.Application
object. Does anyone know a relaible way to check for this among all
versions of Excel? I can't seem to find a steady registry key or
file location that I know will always be there for any version.
Thanks.

Mark



--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Checking for existence of excel


ouch.. you're totally correct re the addins.
(the clsid starts excel with /automation switch)


I remember having problems with this before, but it might have been with
powerpoint.. or maybe with a machine with just xl97??


At least the extra line of code will prevent loading double instance of
excel :)


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


Dave Peterson wrote:

None of my addins were loaded when I started excel this way.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for the existence of a worksheet Allen Excel Discussion (Misc queries) 1 January 20th 10 06:57 PM
Checking for the existence of a characted in a string Peter Rooney Excel Discussion (Misc queries) 2 June 21st 06 10:16 AM
Checking for existence of excel keepITcool Excel Programming 0 June 24th 04 06:07 PM
Checking for the Existence of a Folder Viswanath Tumu Excel Programming 2 April 19th 04 08:31 AM
Checking for existence of macros or code in an Excel Spreadsheet Youssef Mourra Excel Programming 3 August 13th 03 05:13 PM


All times are GMT +1. The time now is 05:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"