简体   繁体   English

vb.net在Internet Explorer和Excel之间更改活动窗口

[英]vb.net Change active window between Internet Explorer and Excel

I'm writing a program in VB.NET that opens Excel and Internet Explorer. 我正在VB.NET中编写一个程序,用于打开Excel和Internet Explorer。 In order to send keys to this programs, I need to bring the window of one of them to the foreground. 为了将密钥发送到该程序,我需要将其中一个的窗口置于前台。 And than to the same with the other one several times. 并且要比其他同一个要好几次。

How can I proceed to do that? 我该怎么做呢?

Code to open Excel: 打开Excel的代码:

xlsApp = New Excel.Application
            xlsApp.Visible = True
            xlsWorkBooks = xlsApp.Workbooks
            xlsWB = xlsWorkBooks.Add() 'Open("T:\Dados_de_Aplicativos\Travel_Finder\texte.xlsx")
            xlsWS = xlsWB.Sheets(1)

Code to open IE: 打开IE的代码:

    Dim IE As SHDocVw.InternetExplorer
    IE = CreateObject("InternetExplorer.Application")

After I open IE, I can put Excel into the foreground doing this: 打开IE后,可以将Excel置于前台:

xlsApp.WindowState = Excel.XlWindowState.xlMinimized
        If xlsApp.WindowState = Excel.XlWindowState.xlMinimized Then
            xlsApp.WindowState = Excel.XlWindowState.xlMaximized
        End If

But I'm not finding similar method to the IE Browser. 但是我没有找到与IE浏览器类似的方法。

Can you please give me an example if there is a solution? 如果可以解决,请给我一个例子吗?

The easiest way would be to use 'AppActivate' using the name of the application or his PID. 最简单的方法是使用应用程序名称或其PID使用“ AppActivate”。 Something like : AppActivate("Application Title") or AppActivate(PID), but if the window is minimized, it won't work. 类似于:AppActivate(“ Application Title”)或AppActivate(PID),但是如果窗口最小化,它将无法工作。

This post How to restore a minimized window using AppActivate(ProcessID) can help you. 这篇文章如何使用AppActivate(ProcessID)恢复最小化的窗口可以为您提供帮助。

You could also use Pinvoke. 您也可以使用Pinvoke。

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

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