Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011
    Posts
    17

    Unanswered: automate import of text file

    Hi,

    I am new to Excel VBA so I need some help.

    I have created a macro that imports a text file in excel.
    What I am wondering of, how can I get the file dialog to open when I start the macro to select the file that I want to import?

    Best Regards
    Geir Arne

    The VBA Code:

    Sub Makro1()
    '
    ' Makro1 Makro
    '

    '
    With ActiveSheet.QueryTables.Add(Connection:= _
    "TEXT;F:\_EP\EPAB\Prosjekter\TOP\TOP uttak Desember\nanodrop\Ferdig med disse nanodrop filer\DirekteUttak1.txt" _
    , Destination:=Range("$A$2"))
    .Name = "DirekteUttak1"
    .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 = 34
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = True
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = False
    .TextFileSpaceDelimiter = False
    .TextFileColumnDataTypes = Array(9, 9, 1, 9, 9, 9, 1, 9, 9, 9, 1, 1, 9, 9, 9, 9, 9)
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False
    End With
    End Sub

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You want to use the FileSystemObject.

    Here's an MS Access example of how to use it: http://www.dbforums.com/microsoft-ac...ml#post6280858
    George
    Home | Blog

Posting Permissions

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