標題:
請教VBA SQL語法內的工作表,可否用變數代替?
[打印本頁]
作者:
newsoft
時間:
2018-5-28 08:46
標題:
請教VBA SQL語法內的工作表,可否用變數代替?
Set myCon = CreateObject("ADODB.Connection")
myCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
Sql = "SELECT * FROM
[His$]
"
His 是工作表名稱, His 能否用變數代替?
感謝指教...
作者:
GBKEE
時間:
2018-6-19 08:37
回復
1#
newsoft
Option Explicit
Sub Ex()
Dim myCon As Object, Sql As String, Sh_Name As String
Set myCon = CreateObject("ADODB.Connection")
myCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
Sh_Name = ThisWorkbook.Sheets(1).Name '
Sql = "SELECT * FROM [" & Sh_Name & "$]"
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)