如何使用Access VBA代码将表导出为CSV格式?
我可以导出为csv格式,但是我需要在csv文件中不带引号的输出。
实际结果:
"scenario 1",17.00,100.00,"75",20.00,"Albert","Detweiler",13-04-1963 0:00:00,"123 Main","Mesa","AZ",85282.00
"scenario 2",16.00,75.00,"A3",5.24,"Benjamin","Detweiler",06-07-1973 0:00:00,"123 Main","Mesa","AZ",85282.00
预期结果:
scenario 1,17.00,100.00,75,20.00,Albert,Detweiler,13-04-1963 0:00:00,123 Main,Mesa,AZ,85282.00
scenario 2,16.00,75.00,A3,5.24,Benjamin,Detweiler,06-07-1973 0:00:00,123 Main,Mesa,AZ,85282.00
请有人帮忙解决这个问题。预先感谢!
示例代码:
Option Compare Database
Sub exportQuery()
Dim exportSQL As String
Dim db As DAO.Database, qd As DAO.QueryDef
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogSaveAs)
Set db = CurrentDb
'Check to see if querydef exists
For i = 0 To (db.QueryDefs.Count - 1)
If db.QueryDefs(i).Name = "Sheet1" Then
db.QueryDefs.Delete ("Sheet1")
Exit For
End If
Next i
Set qd = db.CreateQueryDef("Sheet8", exportSQL)
'Set intial filename
fd.InitialFileName = "export_" & Format(Date, "mmddyyy") & ".csv"
If fd.Show = True Then
If Format(fd.SelectedItems(1)) <> vbNullString Then
DoCmd.TransferText acExportDelim, "Standard Output ", "Sheet1", fd.SelectedItems(1), False
End If
End If
'Cleanup
db.QueryDefs.Delete "Sheet1"
db.Close
Set db = Nothing
Set qd = Nothing
Set fd = Nothing
End Sub