|
OSの処理ですから、Excelのコードでは及びません。全てAPIの処理になります。
例えばどんなウィンドウを開いていても IE を見つけて前面に出す、という
ことなら
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, _
lPalam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) _
As Long
Declare Function OpenIcon Lib "user32" (ByVal hWnd As Long) As Long
Declare Function IsIconic Lib "user32" (ByVal hWnd As Long) As Long
Sub MyWindow_SetFront()
Dim Ret As Long
Ret = EnumWindows(AddressOf Rekkyo, 0)
End Sub
Public Function Rekkyo(ByVal Handle As Long) As Boolean
Dim Ret As Long, Leng As Long, hWnd As Long
Dim Name As String
Name = String(255, ChR(0))
Leng = Len(Name)
Ret = GetWindowText(Handle, Name, Leng)
If Ret <> 0 Then
If Name Like "*Microsoft Internet Explorer*" Then
hWnd = FindWindow(vbNullString, Name)
SetForegroundWindow hWnd
If IsIconic(hWnd) Then OpenIcon hWnd
Exit Function
End If
End If
Rekkyo = True
End Function
こんな感じになります。MyWindow_SetFront を実行してみて下さい。
なお、IE ならもう少し簡単に・・
Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) _
As Long
Declare Function OpenIcon Lib "user32" (ByVal hWnd As Long) As Long
Declare Function IsIconic Lib "user32" (ByVal hWnd As Long) As Long
Sub IE_SetFront()
Dim MyShell As Object, MyWindow As Object, objIE As Object
Dim hWnd As Long
Set MyShell= CreateObject("Shell.Application")
For Each MyWindow In MyShell.Windows
If TypeName(MyWindow.document) = "HTMLDocument" Then
Set objIE = MyWindow: Exit For
End If
Next
If Not objIE Is Nothing Then
hWnd = objIE.hwnd
SetForegroundWindow hWnd
If IsIconic(hWnd) Then OpenIcon hWnd
End If
Set objIE = Nothing: Set MyShell = Nothing
End Sub
でも出来ますが。
|
|