Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Sub Command1_Click() Dim Handle As Long ' 窗口句柄 Handle = FindWindow("XLMAIN", vbNullString) ' 获得窗口句柄 If Handle = 0 Then MsgBox "Excel没启动" Else MsgBox "Excel已经启动!" End Sub
你的程序写的有问题,你可以使用已经打开的实例,在vb 中应该可以这样set exlapp=getobject("EXCEL.SHEET","你要使用的EXCEL文件名") 你想报错的话,只要判断exleapp is nothing 就可以了
Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Sub Command1_Click() Dim Handle As Long ' 窗口句柄 Handle = FindWindow("XLMAIN", vbNullString) ' 获得窗口句柄 If Handle = 0 Then MsgBox "Excel没启动" Else MsgBox "Excel已经启动!" End Sub 没错的 !!!!
If Err <> 0 Then .......
endif
当有错误的时候就能提示你了
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Sub Command1_Click()
Dim Handle As Long ' 窗口句柄
Handle = FindWindow("XLMAIN", vbNullString) ' 获得窗口句柄
If Handle = 0 Then MsgBox "Excel没启动" Else MsgBox "Excel已经启动!"
End Sub
你想报错的话,只要判断exleapp is nothing 就可以了
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Sub Command1_Click()
Dim Handle As Long ' 窗口句柄
Handle = FindWindow("XLMAIN", vbNullString) ' 获得窗口句柄
If Handle = 0 Then MsgBox "Excel没启动" Else MsgBox "Excel已经启动!"
End Sub
没错的 !!!!