它運行時沒有任何錯誤訊息,但檔案未在 MS 訪問中加載。可能是什么原因?我在目錄中有一個 csv 檔案
編輯后
Option Compare Database
選項顯式
公共函式 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
結束功能
uj5u.com熱心網友回復:
您需要在路徑和檔案名之間添加反斜杠。你可以寫
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/429083.html
