0

有没有办法确定 excel 文件是否在 vb.net 中打开?当我用我的程序打开某个文件并在关闭表单之前关闭excel文件时,我的表单根本不会关闭。任何形式的见解都会有所帮助,谢谢。

这控制表单上的关闭按钮

Private Sub Form_FormClosing(ByVal sender As System.Object, _
            ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    If (fileOpen = False) Then
        e.Cancel = False
    Else
        xlWorkbook.Save()
        xlApp.Quit()
    End If

End Sub

所以我把它改成了这个,它出于某种原因工作

 Private Sub Form_FormClosing(ByVal sender As System.Object, _
         ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    If (fileOpen = False Or fileOpen = True) Then
        e.Cancel = False
    Else
        xlWorkbook.Save()
        xlApp.Quit()
    End If

End Sub

当文件被选择并在 excel 中打开时,“fileOpen”设置为 True。我认为它不会被放回 False 除非它在 ​​Excel 关闭时自动执行?

4

0 回答 0