Importing text file not replacing data

Posted on 2012-08-27
Last Modified: 2012-08-27
Sub Workbook_Open()
    filename = "G:\RTMCOMM\Entity.csv"
    Set ws = Worksheets("Entity")
    Set qt = ws.QueryTables.Add("TEXT;" & filename, ws.Range("A1"))
    qt.TextFileConsecutiveDelimiter = False
    qt.TextFileTabDelimiter = False
    qt.TextFileSemicolonDelimiter = True
    qt.TextFileCommaDelimiter = True
    qt.TextFileSpaceDelimiter = False
End Sub

Open in new window

I am using the above to bring in a text file on open.
However, rather than replacing the existing text, it is moving to the next open column and pasting there.

Should I clear the contents before closing?
Question by:Euro5
    LVL 24

    Accepted Solution

    If the filename stays the same everytime, just right click your table (anywhere in the data) and click "Refresh"
    This will re-extract the data rather than adding a new querytable.

    or just clear the sheet after setting it:

    Open in new window

    You can set the file to requery on open, and not have to use VBA at all once the querytable is there.

    Author Closing Comment

    That was VERY helpful!! Thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
    Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
    This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now