Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Names not deleted until book closed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lordfoo@hotmail.com - 21 Feb 2006 16:02 GMT
After deleting a query, and deleting its name from the name list, I
can't recreate a query with the same name without closing the workbook.
Here is a sample subroutine that illustrates the problem:

Option Explicit

Sub testA()
   Dim qt          As QueryTable
   Dim nameEntry   As Name

   If Sheets(1).QueryTables.Count = 0 Then
       Set qt = Sheets(1).QueryTables.Add _
                 ("URL; http://www.cnn.com", Range("A1"))
       qt.Name = "FirstQueryName"
       qt.Refresh
   Else
       Sheets(1).QueryTables(1).Delete
       For Each nameEntry In Sheets(1).Names
           nameEntry.Delete
       Next nameEntry
   End If
End Sub

After executing this subroutine the first time, a query with the name
"FirstQueryName" is created.  Upon the second execution, the query is
deleted.  Then, after the third execution, the query is recreated, but
now the name is "FirstQueryName_1", even though the name has been
deleted from the name list!  What am I missing?

This problem does NOT occur if I close and re-open the workbook between
the second and third invocations of the subroutine.
eseitomer@gmail.com - 21 Feb 2006 17:55 GMT
Very strange.
I did renamed qt.Name = "FirstQueryName_1"
and it maintains that name no matter how many times I ran the macro.

For some reason it keeps it as a count. If we just go right in and name
it so, then there aren't any problems.
Very strange indeed. I will keep looking for solutions.

-E

> After deleting a query, and deleting its name from the name list, I
> can't recreate a query with the same name without closing the workbook.
[quoted text clipped - 27 lines]
> This problem does NOT occur if I close and re-open the workbook between
> the second and third invocations of the subroutine.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.