+ Reply to Thread
Results 1 to 2 of 2

macro to import csv file

  1. #1
    Registered User
    Join Date
    10-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    54

    macro to import csv file

    Hi

    please help me in writing a macro to import csv file in macro by clicking a button.

    thanks a mton in advance.

  2. #2
    Registered User
    Join Date
    10-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: macro to import csv file

    I have tried with the following code, but there are some errors. i am new to macro so please help.



    Sub GetCSVList()
    Dim dlgOpen As FileDialog
    Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
    With dlgOpen
    .AllowMultiSelect = True
    ''Start in
    .InitialFileName = "C:\Users\wasim.anjum\Desktop\Scripwise Exposure"
    .Show
    End With

    For Each fname In dlgOpen.SelectedItems
    ImportCSV fname
    Next
    End Sub

    Sub ImportCSV(fname)
    Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
    ws.Name = "temp" & Worksheets.Count + 1

    With ws.QueryTables.Add( _
    Connection:="TEXT;" & fname, _
    Destination:=Range("A1"))
    .Name = "Temp" & Worksheets.Count + 1
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = xlMacintosh
    .TextFileStartRow = 1
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = False
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = True
    .TextFileSpaceDelimiter = False
    .Refresh BackgroundQuery:=False
    '.UseListObject = False
    End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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