[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Importing text file not replacing data

Posted on 2012-08-27
2
Medium Priority
?
247 Views
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
    qt.Refresh
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?
Thanks!
0
Comment
Question by:Euro5
2 Comments
 
LVL 24

Accepted Solution

by:
Steve earned 2000 total points
ID: 38336606
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:
ws.Cells.clearcontents

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.
0
 

Author Closing Comment

by:Euro5
ID: 38336836
That was VERY helpful!! Thanks!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
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.

834 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