Code change to current excel import format

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Code change to current excel import format

Post by Leesha »

Hi,
I'm using this code to import excel files. The files were originally in 97 format but are now xlsx. I'm not sure how the code needs to be changed.

Code: Select all

    strFolder = "C:\xxxxx\Import\TTTSMDailyFile\"
    strFile = Dir(strFolder & "*.xls")
    Do While strFile <> ""
        DoCmd.TransferSpreadsheet _
            TransferType:=acImport, _
            SpreadsheetType:=acSpreadsheetTypeExcel97, _
            TableName:="tblCSVImportTemp", _
            FileName:=strFolder & strFile, _
            HasFieldNames:=True
            'Range:="Import"
        strFile = Dir
    Loop
Thanks!

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Code change to current excel import format

Post by HansV »

You need to change *.xls to *.xlsx and acSpreadsheetTypeExcel97 to acSpreadsheetTypeExcel12Xml:

Code: Select all

    strFolder = "C:\xxxxx\Import\TTTSMDailyFile\"
    strFile = Dir(strFolder & "*.xlsx")
    Do While strFile <> ""
        DoCmd.TransferSpreadsheet _
            TransferType:=acImport, _
            SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
            TableName:="tblCSVImportTemp", _
            Filename:=strFolder & strFile, _
            HasFieldNames:=True
            'Range:="Import"
        strFile = Dir
    Loop
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Code change to current excel import format

Post by Leesha »

Thanks Hans!
I figured I'd need to change the .xls but even when I tried that I got an error because I didn't know what to put in for the second part. I appreciate the help.
Leesha