使用IE浏览器与Visual Basic [英] Using an IE browser with Visual Basic

查看:185
本文介绍了使用IE浏览器与Visual Basic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

努力找到一个解决方案。
从Visual Basic(Excel中更具体的VBA)我可以使用



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ > AppActivate(我的页面标题 - Windows Internet Explorer)

它每次都很好用。 / p>

我可以打开一个新窗口并发送一个url给它使用..

  Dim ie As Object 
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigatehttp:// websiteurl

而且还可以正常运行
但是每次打开一个新的浏览器,我希望它总是调用同一个窗口。



所以我可以设置 ie 等于同一页面每次。因此,而不是

  Set ie = New InternetExplorer 

它执行类似于

  Set ie = ACTIVE InternetExplorer 

(虽然似乎不存在)。
有一些方法可以设置 ie AppActivate(我的页面标题 - Internet Explorer)相同



谢谢



全部代码在这里:

  Sub Find_Recordings()
Dim MyAppID,ReturnValue

AppActivate(我的页面标题 - Windows Internet Explorer)

SendKeys(^ a)
Application.Wait(Now + TimeValue(0:00:01))
SendKeys(^ c)
Application.Wait现在+ TimeValue(0:00:01))

AppActivate(Microsoft Excel)
表格(DataSearcher)。选择
范围(K1) 。选择
ActiveSheet.PasteSpecial格式:=Text,Link:= False,DisplayAsIcon:= False

范围(A1)。选择

Dim ie As Object
Set ie = New InternetExplorer
ie.Visible = True ie.Navigatehttp:// wwwmyurl

Do Until ie.ReadyState = READYSTATE_COMPLETE
循环

ie.Document.getElementById(searchdata1)。Value = Range(J1)
ie.Document.getElementById(libr ary)Value =RECORDINGS
ie.Document.searchform.Submit



End Sub
/ pre>

解决方案

你可以尝试这样的东西,大量地在重用Internet Explorer COM Automation Object 来标识IE的实例,然后您正在寻找的具体网页处于活动状态。



更改

strURL =http://www.theage.com.au/


我的页面标题 - Windows Internet Explorer
必要


VBA

  Sub Test()
Dim ShellApp As Object
Dim ShellWindows As Object
Dim IEObject As Object
Dim strURL As String
strURL =http://www.theage.com.au/
设置ShellApp = CreateObject(Shell.Application)
设置ShellWindows = ShellApp.Windows()
Dim i
对于i = 0到ShellWindows。 Count - 1
如果InStr(ShellWindows.Item(i).FullName,iexplore.exe)<> 0然后
如果ShellWindows.Item(i).LocationURL = strURL然后
设置IEObject = ShellWindows.Item(i)
MsgBoxIE实例与& strURL& 找到
退出
结束如果
结束如果
下一个
结束Sub


Struggling to find a solution to this one. From Visual Basic (VBA in Excel more specifically) I'm able to call an Internet Explorer window by title using

AppActivate ("My Page Title - Windows Internet Explorer")

And it works great each time.

I can open a new window and send a url to it using..

Dim ie As Object
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://websiteurl"

And that also works okay But it opens a new browser each time and I want it to always calls the same window.

So can i Set ie to equal the same page each time. So instead of

Set ie = New InternetExplorer

It does something like

Set ie = ACTIVE InternetExplorer

(though that doesn't seem to exist). Is there some way of setting ie to be the same as AppActivate ("My Page Title - Internet Explorer") ?

Thanks

Full Code here:

Sub Find_Recordings()
Dim MyAppID, ReturnValue

AppActivate ("My Page Title - Windows Internet Explorer")

SendKeys ("^a")
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys ("^c")
Application.Wait (Now + TimeValue("0:00:01"))

AppActivate ("Microsoft Excel")
Sheets("DataSearcher").Select
Range("K1").Select
ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon: = False

Range("A1").Select

Dim ie As Object
Set ie = New InternetExplorer
ie.Visible = True     ie.Navigate "http://wwwmyurl"

Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop

ie.Document.getElementById("searchdata1").Value = Range("J1")
ie.Document.getElementById("library").Value = "RECORDINGS"
ie.Document.searchform.Submit



End Sub

解决方案

You could try something like this, drawing heavily on reusing Internet Explorer COM Automation Object to identify an instance of IE with then specific web page active that you are looking for.

Change
strURL = "http://www.theage.com.au/"
to

"My Page Title - Windows Internet Explorer" as necessary

VBA

Sub Test()
Dim ShellApp As Object
Dim ShellWindows As Object
Dim IEObject  As Object
Dim strURL As String
strURL = "http://www.theage.com.au/"
Set ShellApp = CreateObject("Shell.Application")
Set ShellWindows = ShellApp.Windows()
Dim i
For i = 0 To ShellWindows.Count - 1
    If InStr(ShellWindows.Item(i).FullName, "iexplore.exe") <> 0 Then
        If ShellWindows.Item(i).LocationURL = strURL Then
            Set IEObject = ShellWindows.Item(i)
            MsgBox "IE instance with " & strURL & " found"
            Exit For
        End If
    End If
Next
End Sub

这篇关于使用IE浏览器与Visual Basic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆