2015-05-27 98 views
1

我連接到Excel表單,該表單充當數據庫。我需要選擇一些記錄與在那裏的條件,但我得到的錯誤:通過使用下面的代碼爲Excel數據源選擇語句

No value given for one or more required parameters

Dim conn As Object 
Dim rs As ADODB.Recordset 
Set rs = New ADODB.Recordset 
Set conn = CreateObject("ADODB.Connection") 
XLName = "C:\Users\X\Desktop\rawdata.xlsx" 
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & 
XLName & "';Extended Properties='Excel 12.0;HDR=NO;IMEX=1';" 
conn.Open connString 
rs.Open ("SELECT * FROM [data$] where industry='Government'"), conn, 
adOpenDynamic, adLockReadOnly 
Sheet1.Range("A2").CopyFromRecordset rs 
rs.Close 
conn.Close 
+1

您確定「下面的代碼」是**完全**您在Visual Basic編輯器中有什麼?因爲沒有'_'行的延續,那代碼就無法編譯。 –

回答

1

當您設定HDR = NO,從Excel表格的列標題將被忽略它將被用於內部名稱。查看較舊的答案:c#, oledb connection string issue

+0

完美只是改爲HDR =是的它現在工作 – Diwakar2u