0

我正在研究从 Excel 打开文件的过程。我想插入一个检查,如果用户在没有选择文件的情况下按打开,那么会有一个消息框弹出警告。

这是我要插入支票的代码的一部分。我尝试使用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
4

1 回答 1

2

不知道你到底要什么,但这是我打开文件时使用的代码,如果他们不选择一个,它不会让他们。

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
于 2013-09-28T00:34:43.220 回答