可以通过VBA代码来解决该问题,具体方法如下:
在VBA窗口中打开你想要保存为CSV文件的Access查询或表。
添加以下代码:
Private Sub CommandButton1_Click() Dim strFileName As String Dim objFile As Object Dim strLine As String Dim i As Integer, j As Integer
strFileName = "c:\temp\result.csv"
Set objFile = CreateObject("Scripting.FileSystemObject").CreateTextFile(strFileName)
' 打印列名
For i = 0 To Me.Recordset.Fields.Count - 1
strLine = strLine & """" & Me.Recordset.Fields(i).Name & ""","
Next i
strLine = Left(strLine, Len(strLine) - 1)
objFile.WriteLine strLine
' 打印数据
With Me.Recordset
.MoveFirst
Do While Not .EOF
strLine = ""
For i = 0 To Me.Recordset.Fields.Count - 1
strLine = strLine & """" & Me.Recordset.Fields(i).Value & ""","
Next i
strLine = Left(strLine, Len(strLine) - 1)
objFile.WriteLine strLine
.MoveNext
Loop
.Close
End With
objFile.Close
MsgBox "已完成导出!"
End Sub
将代码中的'c:\temp\result.csv”改为你想要保存CSV文件的路径。
运行代码并点击保存按钮。
等待程序完成,CSV文件将保存至你指定的路径,并且字段名称将不会改变。