灾难性故障 EXCEL VBA - 错误“-2147418113 (8000ffff)”

Catastrophic Failure EXCEL VBA - error '-2147418113 (8000ffff)'

我正在努力寻找有关

的相关信息

'run-time error '-2147418113 (8000ffff)' - Catastrophic Failure'

我正在经历

Sub GenerateAIA_Click()
Dim SQL_query, SQL_syntax, DB_path, setting_conn As String
Dim conn As New ADODB.Connection
Dim query_rslt As New ADODB.Recordset

Dim mth, mth_yr As Variant
Dim dt As Date
Dim i, bol As Integer
Dim temp1, temp2 As Variant

dt = Sheets("Main").Range("C4")
mth_yr = MonthName(Month(Sheets("Main").Range("I12")), False) & " " & Year(Sheets("Main").Range("I12"))

ThisWorkbook.Sheets("AIA").Select

DB_path = ThisWorkbook.FullName 'Refering the same workbook as Data Source
setting_conn = "Provider=MSDASQL.1;DSN=Excel Files;DBQ=" & DB_path & ";HDR=Yes';"
conn.Open setting_conn
SQL_syntax = "SELECT * FROM [Setup$]"   'Your SQL Statement (Table Name= Sheet Name=[Sheet1$])
query_rslt.Open SQL_syntax, conn

我也注意到这个错误显示在行

conn.Open setting_conn

我使用 excel 2016 以及我的文件格式 .xlsm
有人知道为什么会这样吗?

您的连接字符串似乎有问题。 这是我如何让它工作的:

(首先确保添加对 Microsoft Active-X 数据 Objects 库的引用)

Sub test()
  Dim conn As New ADODB.Connection
  Dim rs As New ADODB.Recordset

  conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\PC\test.xlsm;Extended Properties=""Excel 12.0 Macro;HDR=NO"";"
  conn.Open

  rs.Open "SELECT * FROM [Sheet1$]", conn

  If Not rs.EOF Then
    MsgBox rs(0) ' display the value of the first field in the first row
  Else
    MsgBox "No records found."
  End If

  rs.Close
  conn.Close

End Sub

以我为例,将文件名更改为您的 XLSM 文件,并将 sheet 名称更改为您的 sheet 名称(在其末尾添加 $

如果你的 sheet 现在有 header 个名字,使用 HDR=Yes,如果没有,HDR=No

或者您可以更改显示器的显示分辨率