Excel 文件未在 MS 访问中加载
Excel file does not load in MS access
它运行时没有任何错误消息,但文件未加载到 MS 访问中。可能是什么原因?我在目录中有一个 csv 文件
编辑后
Option Compare Database
选项显式
Public 函数 import_date_files()
Dim report_path As String, file_name As String
report_path = "C:\Users\gobro7\MS access test\weekly_load\"
file_name = Dir(report_path & "*.xlsx")
Do While file_name <> vbNullString
DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, ".xlsx", "")), report_path & file_name, True
file_name = Dir
Loop
MsgBox "Data loaded", vbInformation
结束函数
您需要在路径和文件名之间添加一个反斜杠。你可以写
file_name = Dir(report_path & "\*.csv")
Do While file_name <> vbNullString
DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, ".csv", "")), report_path & "\" & file_name, True
file_name = Dir
Loop
或者您在路径定义的末尾添加反斜杠:
' Note the trailing backslash!
report_path = "C:\Users\gobro7\OneDrive - Levi Strauss & Co\MS access test\weekly_load\"
file_name = Dir(report_path & "*.csv")
Do While file_name <> vbNullString
DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, ".csv", "")), report_path & file_name, True
file_name = Dir
Loop
它运行时没有任何错误消息,但文件未加载到 MS 访问中。可能是什么原因?我在目录中有一个 csv 文件
编辑后
Option Compare Database
选项显式
Public 函数 import_date_files()
Dim report_path As String, file_name As String
report_path = "C:\Users\gobro7\MS access test\weekly_load\"
file_name = Dir(report_path & "*.xlsx")
Do While file_name <> vbNullString
DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, ".xlsx", "")), report_path & file_name, True
file_name = Dir
Loop
MsgBox "Data loaded", vbInformation
结束函数
您需要在路径和文件名之间添加一个反斜杠。你可以写
file_name = Dir(report_path & "\*.csv")
Do While file_name <> vbNullString
DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, ".csv", "")), report_path & "\" & file_name, True
file_name = Dir
Loop
或者您在路径定义的末尾添加反斜杠:
' Note the trailing backslash!
report_path = "C:\Users\gobro7\OneDrive - Levi Strauss & Co\MS access test\weekly_load\"
file_name = Dir(report_path & "*.csv")
Do While file_name <> vbNullString
DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, ".csv", "")), report_path & file_name, True
file_name = Dir
Loop