简体   繁体   English

自动化Internet Explorer后如何将Excel窗口置于前台?

[英]How can I bring the Excel window to the foreground after automating Internet Explorer?

I've seen similar questions asked before but there has never been a clear solution. 我以前曾问过类似的问题,但是从来没有一个明确的解决方案。 I'm trying to bring the Excel window into focus in the foreground without closing Internet Explorer and it works perfectly fine in Debug mode but not when actually running it. 我试图在不关闭Internet Explorer的情况下使Excel窗口成为前台焦点,并且它在“调试”模式下工作得很好,但是在实际运行时却不能。 I've tried AppActivate "Excel" already but that just makes the Excel icon at the bottom of the screen blink. 我已经尝试过AppActivate "Excel"但这只是使屏幕底部的Excel图标闪烁。 Then I found this but I can't get it working 然后我发现了这个,但我无法正常工作

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

Try this 尝试这个

sub test()
    AppActivate "Microsoft Excel"
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM