Consulting

Results 1 to 3 of 3

Thread: Need help with writing a program for importing data into Excel worksheet!

  1. #1
    VBAX Newbie
    Joined
    Oct 2008
    Posts
    5
    Location

    Need help with writing a program for importing data into Excel worksheet!

    I have to write a program that imports data-files from TSPLIB. It has to be possible for the user to choose the file which here after gets imported into a worksheet in Excel. Because the data from the file has to be used in further assignments, it would be it best if the data gets arranged so that the first 5 rows of text (from the imported data) are placed in the first column of the excel worksheet and each of the 3 columns of numbers (from the imported data) have each their own colum in the excel worksheet.)

    I?ve gotten this far with the macro-recorder I just don?t know how to make it dynamic, so the user is able to choose which file is to be imported. Any help would be greatly appreciated !

    Sub Makro1()

    With ActiveSheet.QueryTables.Add(Connection:= _
    "TEXT;C:\Documents and Settings\Nunu\Desktop\EksOpgDataE08\TSPLIB\a280.tsp" _
    , Destination:=Range("A1"))
    .Name = "a280"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = 850
    .TextFileStartRow = 1
    .TextFileParseType = xlFixedWidth
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = True
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = False
    .TextFileSpaceDelimiter = False
    .TextFileColumnDataTypes = Array(1, 1, 1)
    .TextFileFixedColumnWidths = Array(3, 4)
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False
    End With

    End Sub

  2. #2
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    Hi Nunu,

    Try something like this with a COPY of your workbook.

    [VBA]

    Dim fName As String

    fName = "TEXT;" & Application.GetOpenFilename

    With ActiveSheet.QueryTables.Add(Connection:=fName, Destination:=Range("A1"))

    ' etc
    [/VBA]
    Cheers,

    dr

    "Questions, help and advice for free, small projects by donation. large projects by quote"

    http:\\www.ExcelVBA.joellerabu.com

  3. #3
    VBAX Newbie
    Joined
    Oct 2008
    Posts
    5
    Location
    Hi rbrhodes,

    Thank you sooooooo much for your help

    Nunu

Posting Permissions

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