Results 1 to 3 of 3

Thread: Import data . txt from desktop no matter which user

  1. #1

    Import data . txt from desktop no matter which user



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi guys, I am looking for a macro that imports a text file located on a desktop for any user. I mean i don't want to change the file link in VBA for any user. Macro should retrieve the Desktop address automatically. File stored in desktop has always the same name. For xp / vista and win 7. Thanks guys.

    Inviato dal mio GT-N7100 utilizzando Tapatalk

  2. #2
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,479
    Articles
    0
    Excel Version
    365
    try something along these lines, tweaking for destination etc. of course:
    Code:
    Sub blah()
    xxx = CreateObject("WScript.Shell").specialfolders("Desktop") & Application.PathSeparator & "YourConstantFilename.txt"
        With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & xxx, Destination:=Range("C10"))
            .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)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
    End Sub

  3. #3
    Thanks a lot. It has worked perfectly. :-)

    Inviato dal mio GT-N7100 utilizzando Tapatalk

Posting Permissions

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