Private Sub cmdOpen_Click()
CommonDialog1.Filter = "Excel???t(*.xlsx)|*.xlsx"
CommonDialog1.DialogTitle = "????"
CommonDialog1.ShowOpen
Me.txtFilePath.Text = CommonDialog1.FileNameDim DBconn As ADODB.Connection
Dim strSQL As String
Dim RS As ADODB.RecordsetSet DBconn = New ADODB.Connection
Set RS = New ADODB.Recordset
DBconn.CursorLocation = adUseClient
strSQL = "SELECT * FROM [Sheet1$]"
DBconn.Open "provider=microsoft.ace.oledb.12.0;extended properties=‘Excel 12.0 Xml; imex=1‘; data source=" & Me.txtFilePath.Text
RS.Open strSQL, DBconn, adOpenDynamic, adLockOptimisticSet dgList.DataSource = RS
dgList.AllowUpdate = TrueEnd Sub
【VB6笔记-01】 读取Excel绑定到DataGrid
时间: 2024-12-11 11:10:05