VBA绑定修改

时间:2014-02-18 12:18:29

标签: excel vba excel-vba

我试图修改ron

给我的示例代码
Sub test()

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

my_url = "http://www.google.com"

With IE
    .Visible = True
    .navigate my_url
    .Top = 50
    .Left = 530
    .Height = 400
    .Width = 400

Do Until Not IE.Busy And IE.readyState = 4
    DoEvents
Loop

End With

' Find the desired url and click
Set Results = IE.document.getElementsByTagName("a")
For Each itm In Results
    If itm.outerhtml = "B.A.C. VII" Then
        itm.Click

        Do Until Not IE.Busy And IE.readyState = 4
            DoEvents
        Loop
        Exit For
    End If
Next
End Sub

现在我不是后期绑定的粉丝所以我试图修改

中的前两个语句
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

并用

替换它们
Dim IE As InternetExplorer.Application
Set IE = New InternetExplorer.Application

但是,即使我在参考文件中激活了Microsoft Internet ControlsMicrosoft HTML Object Library,这对我的代码也不起作用,如下图所示。

为什么?

enter image description here

亲爱的mehow

我已经想到了这个,但它只是让我看错了

enter image description here

1 个答案:

答案 0 :(得分:2)

Dim ie As InternetExplorer
Set ie = new InternetExplorer

因为InternetExplorer是班级名称

enter image description here