2013-09-28 4 views
0

Я работаю над процедурой для открытия файла из Excel. Я хочу вставить проверку, если пользователь нажимает «Открыть» без выбора файла, а затем появляется предупреждение о появлении сообщения.OpenFileDialog - Проверьте, не был ли выбран

Вот часть моего кода, где я хочу вставить чек. Я пробовал использовать Is Nothing, но это не сработало для меня.

  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 

ответ

1

не знаю, что именно вы просите, но это код, я использую при открытии файлов, и если они не выбрать, то он не будет препятствовать им.

Dim ofd As New OpenFileDialog 
    With ofd 
     'select the atributes before opening 
     'the filename (will show in the filename box) 
     .FileName = "" 
     'the title of the window to open a file 
     .Title = "Open File..." 
     'the extension filter 
     .Filter = "Exel Files|*.exel" 
     ''now to open the dialogue and check if OK has been pressed 
     If .ShowDialog = Windows.Forms.DialogResult.OK Then 
      MsgBox("File Opened Sucessfully") 
      'put the code here when they choose a file 
     Else 
      MsgBox("Please Select A File") 
      'put the code here if they click cancel or close 
     End If 
    End With 
Смежные вопросы