vba 如何以编程方式从 MS Access 最大化浏览器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5891853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:10:24  来源:igfitidea点击:

How to maximize a browser from MS Access programmatically?

internet-explorerms-accessvbabrowser

提问by Curtis Inderwiesche

My purpose for maximizing the browser is to provide a connected and seamless experience for the user from their MS Access application to their web application. For this reason I am looking for a solution which maximizes the same instence of the web browser being controlled via the MS Access application.

我最大化浏览器的目的是为用户提供从他们的 MS Access 应用程序到他们的 Web 应用程序的连接和无缝体验。出于这个原因,我正在寻找一种解决方案,它可以最大限度地提高通过 MS Access 应用程序控制的 Web 浏览器的相同实例。

I start by doing something like this:

我首先做这样的事情:

Dim IE As InternetExplorer
Set IE = New InternetExplorer
IE.Navigate2 "\File Location\index.html"
IE.Document.all("txtSearchKey").innertext = SearchKeyValue
IE.Document.all("btnSearchForKey").Click
IE.Visible = True
Set IE = Nothing

But what I want to do is ensure every time this code is run, the browser is also maximized.

但是我想要做的是确保每次运行这段代码时,浏览器也被最大化。

What is the best way to accomplish this programmatically?

以编程方式完成此任务的最佳方法是什么?

回答by Curtis Inderwiesche

I found the following windows API call to be particularly useful in setting the window size of the web browser. This looks like it could also be used with any other windows application for which the window handle is available to as well.

我发现以下 windows API 调用在设置 Web 浏览器的窗口大小时特别有用。这看起来也可以与窗口句柄可用的任何其他 Windows 应用程序一起使用。

Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
            (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2

So, by putting this together at the end of the code in the question above, I made this function call to set the browser size to maximized:

因此,通过将其放在上述问题中的代码末尾,我调用了此函数以将浏览器大小设置为最大化:

apiShowWindow IE.hwnd, SW_MAXIMIZE

回答by Jean-Fran?ois Corbett

If you call the browser using the Shellstatement, you can use the vbMaximizedFocuswindowstyle. Example with Windows Explorer:

如果使用Shell语句调用浏览器,则可以使用vbMaximizedFocuswindowstyle。Windows 资源管理器示例:

Shell "explorer.exe", vbMaximizedFocus