Importing Large CSV File into Excel Using VBA

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
The below code works, but for whatever reason it doesn't seem to recognize the commas which need to be taken into account since the data is comma delimited:

Code:
Sub Import_Large_Textfiles_DAO()
'Note: A reference must be set to Microsoft DAO 3.5 or 3.51
'Note: A reference must be set to Microsoft Scripting Runtime
    Dim stPath As String, stFilename As String, stGetFile As String
    Dim Db As DAO.Database
    Dim Rst As DAO.Recordset
    Dim fsoObj As FileSystemObject
    
    stGetFile = Application.GetOpenFilename("CSVfiles (*.csv),*.CSV", , "Please select a CSVfile...")
    
        
    Application.ScreenUpdating = False
    Set fsoObj = CreateObject("Scripting.FileSystemObject")
    stPath = fsoObj.GetFile(stGetFile).ParentFolder.Path
    stFilename = fsoObj.GetFile(stGetFile).Name
    Set Db = OpenDatabase(stPath, False, True, "TEXT;")
    Set Rst = Db.OpenRecordset("SELECT * FROM " & stFilename)
    While Not Rst.EOF
        Worksheets.Add
        ActiveSheet.Range("A1").CopyFromRecordset Rst, 10
    Wend
    Rst.Close
    Db.Close
    Application.ScreenUpdating = True
End Sub

Any help would be appreciated. I am running on MS 2007.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
what is your list separator set to, control panel > regional settings > numbers
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top