Excel 2003 - VBA - Importing .txt files and unwanted Names

C

C Brandt

I have a spread sheet that I use VBA to import other files. I re-import
every day to keep the sheet up-to-date. In general I identify areas of the
spread sheet with names and access them that way. I have noticed that when I
import a file, it creates a NAME in the spread sheet as is specified by the
third line in the IMPORT routine (example follows). After the first one it
starts appending a number after the name. Very annoying! Since I don't
actively use them:

1) is there any reason that I need this name?
and
2) is there a way to prevent it from occuring?

Thanks,
Craig

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & POSPath & POSName & "", Destination:=Range("D2"))
.Name = "position"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(5, 1, 1, 1, 1, 1, 1)
.Refresh BackgroundQuery:=False
End With
 
J

Joel

After your posted code use this macro to delete the names

For Each MyName In ActiveWorkbook.Names
If InStr(MyName.Name, "position") Then
ActiveWorkbook.Names(MyName.Name).Delete
a = 0
End If
Next MyName
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Macro / VBA help 4-5-12 1
Import data 1
Help with VBA Macro needed 3
Removing DATA Connections 1
VBA: how to get variables into querry code 2
excel importing data 16
Debug Error 3
Help in VBA code! 5

Top