Results 1 to 3 of 3

Import CSV file using variables

Threaded View

Trent_Illician Import CSV file using... 07-19-2012, 03:40 PM
Trent_Illician Re: Import CSV file using... 07-25-2012, 12:58 PM
Chippy Re: Import CSV file using... 07-25-2012, 03:49 PM
  1. #1
    Registered User
    Join Date
    07-19-2012
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    8

    Import CSV file using variables

    Okay, so I'm new to the forum, so here's a quick back ground. I've got medium exp in basic programming, and fairly good with excel, but only been programming macros for a month or so. Anyway, here's what I'm after. I've got a list of filter names in column "A", such as

    WGC
    WGD
    WGE

    each of those names correspond to a folder in the path bellow.

    In a perfect world, I would select one of those cells, and hit a command button that runs a pretty gnarly macro. Part of that macro imports a CSV file to a different sheet. As it is right now, I have to manually select the files, and the closest thing I've been able to manage as a short cut is to have the starting location be the "filters" folder.

    Here's the only part I'm having trouble with, sense the files and folders are all 100% predictable, I'd like it if the file were automatically selected. Here's what I've tried so far.

    Dim FilterName as String
    FilterName = ActiveCell.Value                  ' the active cell's value is name of the relevant folder name
        With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\users\docs\filters\" & FilterName & "\monthlyreturns.csv",Destination:=Range("A1"))
            .FieldNames = True
            .RowNumbers = False
            .TextFilePromptOnRefresh = True
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileStartRow = 1
            .TextFileCommaDelimiter = True
            .Refresh BackgroundQuery:=False
    End With
    Obviously, the bold section is where the problem is. Am I on a fools errand here??
    Last edited by Cutter; 07-25-2012 at 10:22 PM. Reason: Added code tags

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