Friday, 27 September 2013

OpenFileDialog - Check if has not been selected

OpenFileDialog - Check if has not been selected

I am working on a procedure to Open a file from Excel. I want to insert a
check, if the user presses Open without selecting a file, then have a
message box pop warning.
Here is a portion of my code where I want to insert the check. I tried
using Is Nothing, but it did not work for me.
If GetOpenFileName.ShowDialog() =
System.Windows.Forms.DialogResult.OK Then
fileStream = GetOpenFileName.OpenFile()
If (fileStream Is Nothing) Then 'I tried checking here,
but it does not fire.
vmbContinue = MsgBox(strAlert, MsgBoxStyle.RetryCancel
+ MsgBoxStyle.Critical, "No Workbook Seletected")
If vmbContinue = MsgBoxResult.Cancel Then
xlWB.Close(SaveChanges:=False)
Exit Sub

No comments:

Post a Comment