搞了半天,原来是VBA的窗口打开时,FindWindow函数就能找到,否则就找不到.那就换另一种方法吧
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Err.Clear
On Error Resume Next
Dim App As Word.Application
Dim doc As Word.Document
Set App = GetObject(, "Word.application")
If Err.Number = 0 Then
MsgBox "Word已经运行"
Else
Set App = New Word.Application
Set doc = App.Documents.Add
App.Visible = True
Err.Clear
End If
End Sub
FindWindow函数第一个参数是类名,可以用GetClassName函数得到.
[此贴子已经被惊叹不已于2002-4-8 20:31:01编辑过] |