通过在打开之前进行窗口查找,如果查找成功,则调用SetWindowPos 置顶窗体,否则打开
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_SHOWWINDOW = &H40
Private Sub Form_Load()
Dim n As Long, m As Long
Dim sName As String
sName = "1.doc" & " - Microsoft Word" '这里的1.doc 改成你的文件名
n = FindWindow(vbNullString, sName)
If n <> 0 Then
m = SetWindowPos(n, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
Else
'打开Word代码
End If
End Sub