Hello all,
I am having trouble with some code I am writing to handle an Excel spreadsheet. The idea is that the dialog box is displayed which invites the user to select an Excel spreadsheet. Once they have done that, it is opened and a separate function checks to see whether Sheet1 exists returning Nothing if it is not found. The intention being the try/catch block picks it up and gracefully does nothing.
The problem is that when the function returns nothing, the dialog box is still displayed and the sub doesn't seem to exit.
The code is here:
Can anyone tell me where I am going wrong or offer any enhancements?
Many thanks
Cos
I am having trouble with some code I am writing to handle an Excel spreadsheet. The idea is that the dialog box is displayed which invites the user to select an Excel spreadsheet. Once they have done that, it is opened and a separate function checks to see whether Sheet1 exists returning Nothing if it is not found. The intention being the try/catch block picks it up and gracefully does nothing.
The problem is that when the function returns nothing, the dialog box is still displayed and the sub doesn't seem to exit.
The code is here:
VB.NET:
Private Sub ofdFileToTranslate_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ofdFileToTranslate.FileOk
TextBox1.Text = ofdFileToTranslate.FileNames(0)
Dim ws As Excel.Worksheet
objExcelApp = New Excel.Application
objExcelApp.Visible = False
Try
ws = FindSheet("Sheet1", objExcelApp.Workbooks.Open(TextBox1.Text))
'do something...
Catch ex As NullReferenceException
Console.WriteLine("NullReferenceException Caught")
End Try
End Sub
Can anyone tell me where I am going wrong or offer any enhancements?
Many thanks
Cos