Home All Groups Group Topic Archive Search About
Author
15 Nov 2007 6:53 PM
Lorin
VB6SP6
I have code that I wrote that, among other things, opens Excel and Word.
Works OK when Excel and Word are installed on the PC.
I write data to cells, etc.
However, when installed on a PC without one or the other I obviously get an
error when the sub is called.
I need some sample code to show me how to allow the app to run and simply
not permit the Word and/or Excel portions to run (error out).
Maybe generate a messge to the user that these other apps need to be
installed to use that particular feature.
I would like it to be able to use any previous version of Word or Excel.  It
is all simple stuff and newer features of those are not required.

Author
18 Nov 2007 4:47 AM
SMussler
Here are a couple of functions that check if Word or Excel is installed.
I check for Word/Excel when application starts....  My app exits if
Word/Excel
are not installed, as they are necessary.  You could set a Flag...

As far as using earlier version, I think you need to use late binding.
I'd like further info on that myself - I just installed older version of
Office on
my development machine to match clients in my office...

Function WordInstalled() As Boolean
   Dim wObj As Object
   On Error Resume Next

   ' Get existing instance of Word if it exists.
   Set wObj = GetObject(, "Word.Application")

   If Err <> 0 Then
      Err.Clear
      ' If GetObject fails, then use CreateObject instead.
      Set wObj = CreateObject("Word.Application")
      If Err = 0 Then
         WordInstalled = True
      End If
   Else
      WordInstalled = True
   End If
   wObj.Application.Quit
   Set wObj = Nothing
End Function

Function ExcelInstalled() As Boolean
   Dim wObj As Object
   On Error Resume Next

   ' Get existing instance of Word if it exists.
   Set wObj = GetObject(, "Excel.Application")

   If Err <> 0 Then
      Err.Clear
      ' If GetObject fails, then use CreateObject instead.
      Set wObj = CreateObject("Excel.Application")
      If Err = 0 Then
         ExcelInstalled = True
      End If
   Else
      ExcelInstalled = True
   End If

   wObj.Quit
   Set wObj = Nothing
End Function

Show quote
"Lorin" <Lo***@discussions.microsoft.com> wrote in message
news:A0E47F84-D5E1-4F36-998B-999FC3AA6878@microsoft.com...
> VB6SP6
> I have code that I wrote that, among other things, opens Excel and Word.
> Works OK when Excel and Word are installed on the PC.
> I write data to cells, etc.
> However, when installed on a PC without one or the other I obviously get
> an
> error when the sub is called.
> I need some sample code to show me how to allow the app to run and simply
> not permit the Word and/or Excel portions to run (error out).
> Maybe generate a messge to the user that these other apps need to be
> installed to use that particular feature.
> I would like it to be able to use any previous version of Word or Excel.
> It
> is all simple stuff and newer features of those are not required.
>

AddThis Social Bookmark Button