1、Private Sub Btn_export_Click() 'Btn_export是我程序中的导出的按键
On Error GoTo Err_Btn_export_Click:
Dim MyExcel As Object
Dim MyBook As Object
Dim MySheet As Object
Set MyExcel = CreateObject("Excel.Application")
Set MyBook = MyExcel.Workbooks.Add
Set MySheet = MyBook.Sheets(1)
Dim i As Integer
With MySheet
For i = 1 To Rs.Fields.Count 'Rs是我在事先声明的数据集
With MySheet.Cells(1, i)
.Value = Rs.Fields(i - 1).name
.Font.ColorIndex = 2
.Interior.ColorIndex = 55
'.Interior.Pattern = xlSolid
End With
Next i
.Cells(2, 1).CopyFromRecordset Rs
End With
Err_Exit:
MyExcel.Visible = True
Set MySheet = Nothing
Set MyBook = Nothing
Set MyExcel = Nothing
Exit Sub
Err_Btn_export_Click:
Beep
MsgBox Err.Description, 48, Me.Caption
GoTo Err_Exit:
End Sub2 、我用循环一条条删除的do until Rs.eofrs.deleters.updateloop也可以SQL语句3、快捷方式在按钮的CAPTION属性中加上&[快捷键],比如caption="打开&O",即按ALT+O是快捷方式4、可以先查看报错时的Err.Number值,比如其值是<value>