Exclude code of my application

  • Thread starter Thread starter Freddy Coal
  • Start date Start date
F

Freddy Coal

Hi, My application have some modules that use Excel like a external program.
My problem is when the user don't have Excel, I would like exclude the code
that use excel inside my code, because this make me a fatal crash. How I
make that?.

For example, I have the next code:

'-------------
Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

'OTHER CODE HERE
try
Dim m_Excel As new Excel.Application
Working_excel(folder_sel, "", m_Excel) 'Function inside other
module.
Catch ex As Exception
End Try
End Sub
End Class
'--------------

Thanks in advance for any help.

Freddy Coal
 
Hi, My application have some modules that use Excel like a external
program. My problem is when the user don't have Excel, I would like
exclude the code that use excel inside my code, because this make me a
fatal crash. How I make that?.

Aren't you doing any exception handling?

i.e. check if the object was successfully created then continue?

--
 
I see that you already have an Exception handler in the code snippet that
you posted.

Does this error throw up as soon as you try to run the application. Cos, the
refernce to the Excel library will first have to pass in order for the
application to start and execute. Sort of like Early binding. The other
option would be to late bind. But let us know where/at what stage you see
the exception.

Regards,

Trevor Benedict
MCSD
 
Well Trevor, the exception exist when the client don't have Excel; The fail
is general, the program don't start if not found Excel.

EventType: clr20r3
P9: system.invalidoperationexception

The system crash the program, and send the error to Microsoft; My question
is how exclude the code when I know that user don't have Excel, because a
Try Catch don't work in this case.

Thanks in advance for any help.

Freddy Coal
 
set a import to Microsoft.Win32 at the top of your class

Imports Microsoft.Win32



Function IsExcelInstalled() As Boolean
Dim regClasses As RegistryKey = Registry.ClassesRoot
Dim regExcel As RegistryKey =
regClasses.OpenSubKey("Excel.Application")
If regExcel Is Nothing Then
IsExcelInstalled = False
Else
IsExcelInstalled = True

End If
regExcel.Close()
End Function

now before you do your excel stuff you first check if Excel is installed
with the above function

if IsExcelInstalled then

'do your excel stuff here


else

msgbox ("Nag blah Excel not installed on your system blah need to reformat
PC blah bla nag :-) "


end if

Well i guess you get the idea :-)


HTH

Michel Posseth
 
Create a test project to test this out and also remove the reference to the
Excel PIA.

Regards,

Trevor Benedict
MCSD
 
Back
Top