vba 使用 Visual Basic 打开 Internet Explorer 并调整 ie 窗口的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25468744/
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-12 04:22:19  来源:igfitidea点击:

Open Internet Explorer using Visual Basic and re size the ie window

visual-studio-2010vbainternet-explorervisual-studio-2012button

提问by Shiv Patel

Hey I have been stuck on this bug for a long time I hope someone can help, so in my .NET program when you press a button a timer starts which opens up multiple Internet Explorer windows but the problem is that I want each window opened to be a different size which can be done by adding randomness to the size. But I am not sure how to do that. PLEASE HELP!!!

嘿,我已经被这个错误困扰了很长时间了,我希望有人能提供帮助,所以在我的 .NET 程序中,当你按下一个按钮时,一个计时器会启动,它会打开多个 Internet Explorer 窗口,但问题是我希望每个窗口都打开是不同的大小,可以通过在大小上添加随机性来完成。但我不知道该怎么做。请帮忙!!!

this what i have so far

这是我迄今为止所拥有的

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Process.Start("C:\Program Files (x86)\Internet Explorer\iexplore.exe", "www.google.com")
    End Sub 

回答by cyboashu

Your sample code Timer1_Tickis in .Net

您的示例代码Timer1_Tick在 .Net 中

But, if you are looking for VBA solution , try something like this

但是,如果您正在寻找 VBA 解决方案,请尝试这样的操作

  Sub IE()

        Dim oIE As Object

        Set oIE = CreateObject("InternetExplorer.Application")

        oIE.navigate2 "www.google.com"
        oIE.Height = CInt(Int((1000 * Rnd()) + 1))
        oIE.Width = CInt(Int((1000 * Rnd()) + 1))
        oIE.Visible = True

    End Sub

This link might help : http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx

此链接可能会有所帮助:http: //msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx

回答by rahulroy9202

This can be achieved by using interop and USER32.dll

这可以通过使用互操作和 USER32.dll 来实现

Let me give u an example in c#.

让我给你举个 C# 的例子。

    [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll", SetLastError = true)]
    internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

    public IntPtr win_handle;

    void somefunction(){
            string ie_win_class = "IEFrame";
            string ie_win_nm = "New Tab - Windows Internet Explorer";
            win_handle = FindWindow(win_class, win_name);
            MoveWindow(win_handle, 600, 600, 600, 600, True);
     }

sorry, i don't have experience with VB. I hope this helped you.

抱歉,我没有使用 VB 的经验。我希望这对你有帮助。

links-

链接-

MoveWindow function

移动窗口函数

COM Interop (Visual Basic)

COM 互操作 (Visual Basic)