这个很简单!
判断Word是否打开的方法如下:
1、先编写一个函数查找桌面上的所有窗口标题!
2、然后在查得的标题中查找包含“- Microsoft Word”的标题,如果有说明Word已打开,否则没有打开!(这是因为任何一个Word文档的标题都包含 - Micorsoft Word)
函数如下:
'声明
Public Const GW_HWNDFIRST = 0 '子窗口的第一兄弟窗口,其第一个顶层窗口
Public Const GW_HWNDLAST = 1 '子窗口的最后一个兄弟窗口,或最后一个顶层窗口
Public Const GW_HWNDNEXT = 2 '后继窗口
Public Const GW_HWNDPREV = 3 '先前窗口
Public Const GW_OWNER = 4 '窗口拥有者
Public Declare Function GetWindow Lib "user32" (ByVal HWnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal HWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal HWnd As Long) As Long
'函数
Public Sub FindTitle()
'查找桌面上的所有窗口标题
On Error GoTo ErrHandle:
Dim currwnd As Double
Dim ListItem As String
Dim buf As String
Dim buflen As Long
Dim child_hwnd As Long
Dim ret As Long
if instr(ListItem,"- Microsoft Word")<>0 then '或者用 if right(ListItem,16)="- Microsoft Word") then
msgbox"Microsoft Word已打开!"
else
msgbox"Microsoft Word没有打开!"
end if