同上。

解决方案 »

  1.   

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As Any) As Long
    Private Sub Command1_Click()
    Dim hWnd_xl As Long
    hWnd_xl = FindWindow("XLMain", 0&)
    MsgBox hWnd_xl
    End Sub
      

  2.   

    Dim appWorld As Excel.Application
    Err.Clear
    On Error Resume Next
    Set appWorld = GetObject(, "Excel.Application") '查找一个正在运行的 Excel 拷贝
    If Err.Number <> 0 Then 'Excel 没有运行
        Set appWorld = CreateObject("Excel.Application") '运行它
    Else
        appWorld.Visible = True
    End If