Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Adding new name to Names collection

G'Day,

I've noticed that importing a text file via a macro
(using .QueryTables.Add) also adds a new defined range name.

I'd like to delete the new name after it is added to stop an
accumulation of range names.

I haven't noticed any pattern to where the new name is added to the
Names collection - in one test case, with 24 current names, the new
name was added at position number 7.

Can anyone explain how the new names are added to the Names collection
so they can be deleted easily?

I'm not too sure about the naming of the added defined name either.

Thanks,

Clive
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Adding new name to Names collection

Clive

I think the name depends on what you are actually importing.

If you are doing this in code you could actually miss out the Name
part and you'll get something like ExternalData...

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Adding new name to Names collection

Assuming the defined Name is same as the Query name -

Sub test()
Dim sPrefix As String
Dim ws As Worksheet
Dim qt As QueryTable

Set ws = ActiveSheet

On Error Resume Next
sPrefix = ws.Names(1).Name
sPrefix = Left$(sPrefix, InStr(1, sPrefix, "!"))
On Error GoTo 0

For Each qt In ws.QueryTables
If Len(sPrefix) Then
sName = Replace(qt.Name, " ", "_")
ws.Names(sPrefix & sName).Delete
End If
' qt.Delete ' delete the query too?
Next

End Sub

Regards,
Peter T


"dusty" wrote in message
...
G'Day,

I've noticed that importing a text file via a macro
(using .QueryTables.Add) also adds a new defined range name.

I'd like to delete the new name after it is added to stop an
accumulation of range names.

I haven't noticed any pattern to where the new name is added to the
Names collection - in one test case, with 24 current names, the new
name was added at position number 7.

Can anyone explain how the new names are added to the Names collection
so they can be deleted easily?

I'm not too sure about the naming of the added defined name either.

Thanks,

Clive



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Adding new name to Names collection

Peter,

That worked nicely, thank you.

Regards,

Clive
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory leak in names collection? Karri Excel Programming 3 August 8th 06 12:15 PM
adding a VBA name to workbook names collection brachistochrone Excel Programming 4 May 10th 06 12:58 PM
Adding Range to Worksheet Names Collection Keith Willshaw Excel Programming 2 March 5th 04 09:17 AM
Names Collection MarkC[_2_] Excel Programming 2 January 28th 04 10:47 AM


All times are GMT +1. The time now is 06:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"