| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 870 人关注过本帖
标题:请问:怎么修正:实时错误91,“对象变量或with变量未设置”(黄色标向:Se ...
只看楼主 加入收藏
dq8888
Rank: 1
等 级:新手上路
帖 子:15
专家分:5
注 册:2015-5-29
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
请问:怎么修正:实时错误91,“对象变量或with变量未设置”(黄色标向:Set lrow = table.rows(0))
这是获取webbrowser控件网页的表格内容导入数据表中,运行出现:实时错误91,“对象变量或with变量未设置”

Private Sub Command1_Click()
    WebBrowser1.navigate "http://www.

End Sub

Private Sub Form_Load()
    WebBrowser1.Stop
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Dim doc As MSHTML.HTMLDocument
    Set doc = WebBrowser1.document
    Dim table As MSHTML.HTMLTable
    Dim lrow As MSHTML.HTMLTableRow
    Dim cel As MSHTML.HTMLTableCell
    Set table = doc.getElementById("REPORTID_tab1")
    Dim Conn As ADODB.Connection
   
    Dim FLD() As String
    Set Conn = CreateObject("ADODB.Connection")
   
    Conn.Open "provider=microsoft.jet.oledb.4.0;data source=d:\DB1.MDB"
    Set lrow = table.rows(0)
    ReDim FLD(0 To lrow.cells.length) As String
    Dim i As Integer
    Dim tbname As String
    Dim sql As String
    tbname = InputBox("表1", "table1")
    For i = 0 To lrow.cells.length - 1
        FLD(i) = Replace(Replace(Replace(lrow.cells(i).innerText, "/", ""), "(", ""), ")", "")
        sql = sql & FLD(i) & " varchar(255),"
    Next i
    sql = Left(sql, Len(sql) - 1)
    Conn.Execute "create table " & tbname & " (" & sql & ")"
    Dim j As Integer
    sql = ""
    For i = 0 To lrow.cells.length - 1
        sql = sql & FLD(i) & ","
    Next i
    sql = Left(sql, Len(sql) - 1)
    Dim vlist As String
    For i = 1 To table.rows.length - 1
        vlist = ""
        Set lrow = table.rows(i)
        For j = 0 To lrow.cells.length - 1
            vlist = vlist & "'" & lrow.cells(j).innerText & "',"
        Next j
        vlist = Left(vlist, Len(vlist) - 1)
        Conn.Execute "insert into " & tbname & " (" & sql & ") values (" & vlist & ")"
    Next i
   
    Conn.Close

    Set Conn = Nothing
End Sub
搜索更多相关主题的帖子: Object 数据表 黄色 网页 
2015-06-01 16:15
chen3523
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:33
帖 子:223
专家分:1165
注 册:2013-2-12
收藏
得分:2 
我用过的with如下:
          Adodc1.Recordset.AddNew
             With Adodc1
               .Recordset("项目名称") = Trim$(DataCombo1.Text)
               .Recordset("文件名") = Trim$(Text1(0).Text)
               .Recordset("日期") = Trim$(Text1(1).Text)
               .Recordset("存档合号") = Trim$(Text1(2).Text)
               .Recordset("本合序号") = Trim$(Text1(3).Text)
               .Recordset("备注") = Trim$(Text1(4).Text)
               .Recordset.Update
            End With
你的太高深我看不懂,只能提供我觉得简单让你参考。

调试失败3次后,关机睡觉,当醒来时多有收获。
2015-06-01 19:35
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:8 
回复 楼主 dq8888
Dim doc As MSHTML.HTMLDocument
    Dim elem As MSHTML.HTMLBaseElement
    Set doc = WebBrowser1.Document
 ...
    Conn.Open "provider=microsoft.jet.oledb.4.0;data source=d:\test.MDB"
    Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
        DoEvents
    Loop
    For Each elem In doc.All
      If elem.tagName = "TABLE" Then
        Set table = elem
        If table.id = "REPORTID_tab1" Then
          Set lrow = table.rows(iSourceRow)
          Form1.Caption = lrow.cells(0).innerText
          Exit For
        End If
      End If
    Next

大开眼界
2015-06-02 11:28
快速回复:请问:怎么修正:实时错误91,“对象变量或with变量未设置”(黄色标向 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042094 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved