Results 1 to 1 of 1

How to remove header for importing and add file name to a column

Threaded View

  1. #1
    Registered User
    Join Date
    06-23-2016
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    12

    How to remove header for importing and add file name to a column

    I found this code somewhere on the internet, and it is what i need.
    but! is there a way to remove the header and add the FILENAME without extension on last Column?

    Sub ImportTXTFiles()
        Dim fso As Object
        Dim xlsheet As Worksheet
        Dim qt As QueryTable
        Dim txtfilesToOpen As Variant, txtfile As Variant
    
        Application.ScreenUpdating = False
        Set fso = CreateObject("Scripting.FileSystemObject")
    
        txtfilesToOpen = Application.GetOpenFilename _
                     (FileFilter:="ASCII Files (*.asc), *.asc", _
                      MultiSelect:=True, Title:="ASCII Files to Open")
    
        With ActiveSheet
    
            For Each txtfile In txtfilesToOpen
    
                importrow = 1 + .Cells(.Rows.Count, 1).End(xlUp).Row
    
                ' IMPORT DATA FROM TEXT FILE
                With .QueryTables.Add(Connection:="TEXT;" & txtfile, _
                  Destination:=.Cells(importrow, 1))
                    .TextFileParseType = xlDelimited
                    .TextFileConsecutiveDelimiter = False
                    .TextFileTabDelimiter = False
                    .TextFileSemicolonDelimiter = False
                    .TextFileCommaDelimiter = True
                    .TextFileSpaceDelimiter = False
                    '.TextFileOtherDelimiter = ","
                    
                    .Refresh BackgroundQuery:=False
                End With
    
    
            Next txtfile
    
            For Each qt In .QueryTables
                qt.Delete
            Next qt
    
        End With
    
        Application.ScreenUpdating = True
        MsgBox "Successfully imported text files!", vbInformation, "SUCCESSFUL IMPORT"
    
        Set fso = Nothing
    End Sub
    Last edited by ktbjx; 02-16-2022 at 08:08 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Edit VBA code without automatically executing code
    By Andrew Entee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-20-2017, 02:38 PM
  2. [SOLVED] Code for Edit in VBA
    By Chandria in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-14-2017, 03:39 AM
  3. edit in code for populate range of cell in list box and code for delete any items
    By mazan2010 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2017, 03:33 PM
  4. How to edit vba code
    By issa.o in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2017, 02:59 AM
  5. [SOLVED] This code not working in a Protected Sheet, can any one pls edit this code
    By rajeshn_in in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-12-2016, 01:08 AM
  6. Can i avoid Locked Cells Using this Code getting Updated How can i edit this code
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-01-2014, 03:27 AM
  7. Unable to edit macro recording code to be a relative code.
    By holaitsme in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-2014, 10:51 AM

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