+ Reply to Thread
Results 1 to 5 of 5

vba query csv file excel 2010

Hybrid View

  1. #1
    Registered User
    Join Date
    05-12-2013
    Location
    Tenerife,spain
    MS-Off Ver
    Excel 2010
    Posts
    3

    vba query csv file excel 2010

    Trying to run a query on a csv file (* delimeter)
    (Because its bigger than 3M), so can't import the lot!

    problem no.1 - the jet engine doesn't work with 64 bit Office.
    problem no.2 ODBC - don' want every machine to set up ODBC connection; dsn-less connection - driver manager error

    anyone got 'here's one I made earlier' that will run with 64 bit Excel??

    TIA

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: vba query csv file excel 2010

    Hi,

    did you try opening (not importing) the csv file with excel setting the format parameter to csv?
    http://msdn.microsoft.com/en-us/libr.../ff194819.aspx
    Workbooks.Open FileName:=MyFile, Format:=2
    Regards
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    05-12-2013
    Location
    Tenerife,spain
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: vba query csv file excel 2010

    Thought of that; however because the file is bigger than excel can handle, I need to run a quey to return a sub-set of the data before loading/opening the file.
    Also - once opened, using a for .. next loop to enter the result into excel will be slow?

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: vba query csv file excel 2010

    Quote Originally Posted by oldfart101 View Post
    (Because its bigger than 3M)
    So I suppose it's 3 GigaByte here.. shouldn't 64bit Excel open this? Might take some time though

    Once opened you parse all data into an array with one codeline, construct your output in another array and paste it with one codeline, that's faster than looping through all cells.

    Regards

  5. #5
    Registered User
    Join Date
    05-12-2013
    Location
    Tenerife,spain
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: vba query csv file excel 2010

    Sub import_csv()
    ''This requires that you add a reference Microsoft ActiveX Data Objects to support the ADO code.
    ''also need to download & install Microsoft Access Database Engine 2010 Redistributable
    ''AccessDatabaseEngine_x64.exe
    '' from http://www.microsoft.com/en-us/download/details.aspx?id=13255
    
    '' you have to create a schema.ini file in the same directory
    ''[short.csv]           the file name of the csv file
    ''Format=Delimited(*)
    ''ColNameHeader = True
    ''FirstRowHasNames = True
    
    Dim con, rst
    Set con = CreateObject("ADODB.Connection")
    
    '' the directry name is Source
    con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\sourcedir;Extended Properties='Text;HDR=YES;FMT=Delimited*';"
    
    Set rst = CreateObject("ADODB.Recordset")
    
    '' the csv file goes between the [brackets]
    rst.Open "SELECT * FROM [short.csv] WHERE AccountNo=00009819;", con
    
    
    Dim nextRow As Integer
     
    rst.MoveFirst
    nextRow = Worksheets("Sheet1").UsedRange.Rows.Count + 1
    Worksheets("Sheet1").Cells(nextRow, 1).CopyFromRecordset rst
     
    rst.Close
    con.Close
     
    Set rst = Nothing
    Set con = Nothing
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1