我之前看过类似的问题,但从来没有一个明确的解决方案。我正在尝试将Excel窗口放在前台焦点而不关闭Internet Explorer,它在调试模式下工作得很好,但在实际运行时却没有。我已经尝试了AppActivate "Excel"
,但只是让屏幕底部的Excel图标闪烁。然后我找到了这个,但我无法让它工作
Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" _
(ByVal hWnd As LongPtr, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Public Declare PtrSafe Function SetForegroundWindow Lib "user32" _
(ByVal hWnd As Long) As Long
Sub qstn()
Dim IE As New InternetExplorer: IE.navigate "www.cnn.com": IE.Visible = True: apiShowWindow IE.hWnd, SW_MAXIMIZE
LoadIt IE
SetForegroundWindow Application.hWnd
End Sub
Sub LoadIt(ByVal IE As InternetExplorer, Optional ByVal loadmins As Integer = 5)
Do
DoEvents
Loop Until IE.ReadyState = READYSTATE_COMPLETE And IE.Busy = False
End Sub
答案 0 :(得分:0)
试试这个
sub test()
AppActivate "Microsoft Excel"
End Sub