Private Sub Command1_Click()
Dim xlapp As Variant
Dim xlBook As Variant
Dim xlSheet As Variant
Dim sum As Long
Set xlapp = CreateObject("excel.application")
Set xlBook = xlapp.Workbooks.Open(App.Path & "\data\报表.xlt") '打开EXCEL模板
'Set xlBook = xlapp.Workbooks.Add
Set xlSheet = xlBook.worksheets(1)
xlapp.Visible = True
Adodc1.ConnectionString = cn.ConnectionString
Adodc1.RecordSource = "select * from [Sheet1] where 试验号='" & shiyanH & "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
xlSheet.Cells(sum + 1, 2) = shiyanH
For sum = 0 To Adodc1.Recordset.RecordCount - 1
xlSheet.Cells(sum + 3, 1) = Adodc1.Recordset(1)
For j = 2 To 21
If Adodc1.Recordset(j) <> "" Then
If Adodc1.Recordset(j) = "********" Then
xlSheet.Cells(sum + 3, j) = (Adodc1.Recordset(j))
Else
xlSheet.Cells(sum + 3, j) = Val(Adodc1.Recordset(j))
End If
End If
Next
Adodc1.Recordset.MoveNext
Next sum
End If
End Sub
Sub Main()
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\tsdb.mdb;Persist Security Info=False"
frmStart.Show
End Sub
以上是读取Access数据表,导入到Excel的代码。
可以的,私信一下我