以下是引用PJPX在2010-2-3 16:26:08的发言:
在创建EXCEL对象前,能否检测当前是否有活动的EXCEL工作簿,如果有的话,则先关闭所有活动的EXCEL工作簿?
还请各位高手指点,谢谢。
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'--------------------------------------------------------------------
Private Sub Form_Load()
Dim Handle
As Long
'
窗口句柄
Handle = FindWindow("XLMAIN", vbNullString)
'
获得窗口句柄
If Handle = 0 Then
MsgBox "Excel没启动"
Else
If MsgBox("当前有活动Excel工作薄,是否将其关闭?", vbInformation + vbYesNo, "温馨提示") = vbYes Then
Shell "taskkill /f /im excel.exe"
Else
End If
End If
End Sub
[
本帖最后由 xzqsml 于 2010-2-3 17:43 编辑 ]