+ Reply to Thread
Results 1 to 2 of 2

Getting data out of log file automatically

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2009
    Location
    Munich
    MS-Off Ver
    Excel 2007
    Posts
    10

    Getting data out of log file automatically

    Hello,

    I need to write a code that automatically gets data from a machine log file (saved as *.csv). I have already recorded a macro which gets this information out of a specific file with a specific path.

    What I want to have is a code where the user can choose the file himself. I hope you can help me with this. Here is the code:

    Sub Einlesen()
        Range("B4").Select
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;O:\03 Excel\01 Test Einlesen csv\00 .csv" _
            , Destination:=Range("$B$4"))
            .Name = "00 "
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 932
            .TextFileStartRow = 8
            .TextFileParseType = xlFixedWidth
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(9, 1, 9, 1, 9)
            .TextFileFixedColumnWidths = Array(1, 8, 49, 5)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
    End Sub
    I appreciate your support!

    m4rc

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Getting data out of log file automatically

    Have a look at the GetOpenFilename method. This will return the path/file name which you can then use in your code.


    
        fileToOpen = Application _
        .GetOpenFilename("Text Files (*.txt), *.txt")
        If fileToOpen = False Then exit sub
    
    
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;" & fileToOpen  _
            , Destination:=Range("$B$4"))
            .Name = "00 "
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

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