Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I change this vba code so that it works with .xlsx files?

I have the following vba code that works with csv files:

Option Compare Database
Option Explicit

Public Function import_data_files()

Dim report_path As String, file_name As String

report_path = "C:\Users\HBee\Downloads\"

file_name = Dir(report_path & "*.csv", vbDirectory)

Do While file_name <> vbNullString
    DoCmd.TransferText acImportDelim, , Trim(Replace(file_name, ".csv", "")), report_path & file_name, True
    file_name = Dir
Loop

MsgBox "Data files imported.", vbInformation

End Function

How do I make this code work with .xlsx files?. I thought it would be as simple as replacing csv with xlsx but when I do that I get the following error:

Run-time error '31519':
You cannot import this file.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to change TransferText to TransferSpreadsheet.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading