【问题标题】:The Microsoft Office Access database engine could not find the object 'sheet1$'Microsoft Office Access 数据库引擎找不到对象“sheet1$”
【发布时间】:2015-04-20 16:03:23
【问题描述】:

所以,我在 vb6 中创建了一个简单的应用程序。它是将 Excel sheet1 的内容显示到数据网格视图中。

  If CommonDialog1.FileName = "" Then
    Label2.Caption = "No file selected."
  Else
    file_name = CommonDialog1.FileName
    Label2.Caption = file_name
  End If

  Dim cn As New ADODB.Connection
  Dim rs As New ADODB.Recordset

  cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= file_name;Extended Properties=Excel 12.0;"
  If cn.State = adStateOpen Then
          MsgBox "Connected to Excel File"
  End If

  strQuery = "SELECT * FROM `Sheet1$`"   <<Error Highlighted>>

  Set rs = cn.Execute(strQuery)


  rs.Close
  cn.Close

但我收到此错误:

Microsoft Office Access 数据库引擎找不到对象 'sheet1$'。确保对象存在并且您拼写了它的名称和 路径名正确。

【问题讨论】:

标签: excel vb6


【解决方案1】:
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= file_name;Extended Properties=Excel 12.0;"

这里文件名的字面意思是“file_name”——你需要将变量连接到连接字符串中:

cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
          file_name & ";Extended Properties=Excel 12.0;"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多