Results 1 to 2 of 2

Create a macro to import semicolon-delimited text into template

Threaded View

  1. #1
    Registered User
    Join Date
    05-15-2012
    Location
    Salem, Oregon
    MS-Off Ver
    Excel 2007
    Posts
    7

    Create a macro to import semicolon-delimited text into template

    I've tried this a few times using the macro recorder, but the result is always that the macro will only work for the one text file used when it was recorded. Is there an easy way to alter what was recorded, or setup an easy macro to import a file into a template with a userform? I just started working with macros, and this is beyond my capacity right now.

    Attached are the sample text file, and the template that it needs to be imported into.

    Here's the macro as it was recorded:

    Sub TSU_IVR_Reports()
    '
    ' TSU_IVR_Reports Macro
    ' Pulls in data from TSU text files and saves as a new file
    '
    
    '
        ChDir _
            "C:\Documents and Settings\donajose\Desktop\TSU Cycle time\TSU IVR report import"
        Workbooks.Open Filename:= _
            "C:\Documents and Settings\donajose\Desktop\TSU Cycle time\TSU IVR report import\TSU IVR report template.xlsm"
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;C:\Documents and Settings\donajose\Desktop\TSU Cycle time\TSU IVR report import\Example.txt" _
            , Destination:=Range("$A$5"))
            .Name = "20120506_1"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 437
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = True
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        Columns("A:Q").Select
        Range("A3").Activate
        Columns("A:Q").EntireColumn.AutoFit
        Selection.ColumnWidth = 20.29
        Columns("A:Q").EntireColumn.AutoFit
        Range("A2:Q2").Select
        ActiveWorkbook.SaveAs Filename:= _
            "C:\Documents and Settings\donajose\Desktop\TSU Cycle time\TSU IVR report import\TSU IVR Example.xlsm" _
            , FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
    End Sub
    Thanks!
    Attached Files Attached Files

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