Private Sub Command1_Click()
'获取文件名 和保存路径
CommonDialog1.Filter = " 所有文件(*.xls)|*.xls"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowSave
'将数据库表格里的数据 写到excel表格中
Dim i As Integer
Dim j As Integer
Dim ex As Object
Dim exwbook As Object
Dim exsheet As Object
Set ex = CreateObject("Excel.Application") '创建excel工作薄
Set exwbook = Nothing
Set exsheet = Nothing
Set exwbook = ex.Workbooks().Add
Set exsheet = exwbook.Worksheets("sheet1")
For i = 1 To xinxi.Rows
For j = 1 To xinxi.Cols
With ex.Cells(i, j)
.NumberFormatLocal = "@" '初始化 excel表格中单元格数值类型为 文本 类型 即存储字符
End With
ex.Cells(i, j).Value = xinxi.TextMatrix(i - 1, j - 1) '逐行写如excel表格
Next j
Next i
'对保存时的控制
If CommonDialog1.FileName = "" Then
Exit Sub
End If
exwbook.SaveAs CommonDialog1.FileName '保存到指定路径
'退出excel
ex.Quit
MsgBox "保存完毕!"
End Sub
这是我写的数据表格里的数据导出到xls表格里,把xls表格里的数据写进去,只需把写入掉过来!