Dim fs As New FileSystemObject Dim txtFile As TextStream With CommonDialog1 .Filter = "Excel文件(*.xls)|*.xls" .DialogTitle = "导出为" .FilterIndex = 0 .FileName = "" .ShowSave End With
If CommonDialog1.FileName = "" Then Exit Sub End If Ocn.open "" '(打开你要的表) rs.Open "Select * from TableName", Ocn, adOpenDynamic, adLockReadOnly
If rs.EOF = True Then Set rs = Nothing Exit Sub End If
Set txtFile = fs.CreateTextFile(CommonDialog1.FileName, True) txtFile.Write rs.GetString End If Set rs=Nothing txtFile.Close MsgBox "导出成功", , "提示" Unload Me Exit Sub 需引用Microsoft scripting Runtime 添加部件Microsoft Windows Common Controls 6.0
Dim txtFile As TextStream
With CommonDialog1
.Filter = "Excel文件(*.xls)|*.xls"
.DialogTitle = "导出为"
.FilterIndex = 0
.FileName = ""
.ShowSave
End With
If CommonDialog1.FileName = "" Then
Exit Sub
End If
Ocn.open "" '(打开你要的表)
rs.Open "Select * from TableName", Ocn, adOpenDynamic, adLockReadOnly
If rs.EOF = True Then
Set rs = Nothing
Exit Sub
End If
Set txtFile = fs.CreateTextFile(CommonDialog1.FileName, True)
txtFile.Write rs.GetString
End If
Set rs=Nothing
txtFile.Close
MsgBox "导出成功", , "提示"
Unload Me
Exit Sub
需引用Microsoft scripting Runtime
添加部件Microsoft Windows Common Controls 6.0