范例:
Private Sub WB_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    Dim i, j
    Dim xo, yo
    For i = 0 To WB.Document.All.length - 1
        If UCase(WB.Document.All(i).tagName) = "INPUT" Then
            Set xo = WB.Document.All(i)
            If LCase(xo.Type) = "text" Then
                xo.Value = "OKOK"
            End If
        End If
        
        If WB.Document.All(i).tagName = "TEXTAREA" Then
            Set xo = WB.Document.All(i)
            xo.Value = "Textarea"
        End If
    Next i
End SubPrivate Sub Command5_Click()
    Dim vDoc, vTag
    Dim i As Integer
      
    Set vDoc = WB.Document
    
    For i = 0 To vDoc.All.length - 1
        If UCase(vDoc.All(i).tagName) = "INPUT" Then
            Set vTag = vDoc.All(i)
            If LCase(vTag.Type) = "submit" Then
                Debug.Print "sub"
                vTag.Select
                vTag.Click
                Exit Sub
            End If
        End If
    Next i
End SubPrivate Sub Command1_Click()
    WB.Navigate "www.yahoo.com.cn"
End SubWB是Webbrowser控件,点击Command1浏览 Command5点击按钮。首先你需要在
References定义中加入Microsoft HTML Object Library

解决方案 »

  1.   

    微软有个例子,可以通过document来捕获DHTML的事件,但我忘了跟哪找到的了。首先要做个类:VERSION 1.0 CLASS
    BEGIN
      MultiUse = -1  'True
      Persistable = 0  'NotPersistable
      DataBindingBehavior = 0  'vbNone
      DataSourceBehavior  = 0  'vbNone
      MTSTransactionMode  = 0  'NotAnMTSObject
    END
    Attribute VB_Name = "clsForward"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = True
    Attribute VB_PredeclaredId = False
    Attribute VB_Exposed = False
    Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
    Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
    Option Explicit    Dim oObject As Object
        Dim sMethod As String
        Dim bInstantiated As Boolean
    Public Sub Class_Initialize()    bInstantiated = False
      
    End SubPublic Sub Set_Destination(oInObject As Object, sInMethod As String)    Set oObject = oInObject
        sMethod = sInMethod
        bInstantiated = True
      
    End SubPublic Sub My_Default_Method()
    Attribute My_Default_Method.VB_UserMemId = 0    If bInstantiated Then
            CallByName oObject, sMethod, VbMethod
        End If
      
    End Sub'===========================
    然后在你的程序的web_DocumentComplete里加入:
    Dim cfForward As clsForward
        Set cfForward = New clsForward
        cfForward.Set_Destination Me, "DocLink"
        web(index).Document.All("ASUBMIT").onclick = cfForward然后加入你的DocLink函数:
    Public Sub DocLink()
    End Sub
    这里的ASUBMIT是一个超连接的class ID,当点这个超连接时会触发 DocLink
    类似的,按钮什么都一样。
    同样的,通过document对象,你可以访问Webbrowser里的任何对象,比如 inputBox.Value 就象在DHTML/ javascript中做的那样。所要注意的一定要等 Document完全生成、读到内存并显示以后才能这样做,通过on error的技巧可以处理这个随机出现的问题
    多说一句:对于javascript注意大小写。
    再多说一句:给分吧 :)
      

  2.   

    谢谢flywhc了!分已给!!希望以后多多帮忙!