+ Reply to Thread
Results 1 to 2 of 2

Excel 2003 Query Table Deleted on Refresh

Hybrid View

  1. #1
    Registered User
    Join Date
    02-18-2004
    Posts
    71

    Excel 2003 Query Table Deleted on Refresh

    Hi All

    I am using Excel 2003 SP3 and have had an ongoing issue with query tables being deleted after I refresh the data. Sometime ago a kind soul provided me with the following script that seems to work most of the time (but not always) assuming also that I have actually added this into my spreadsheet. Just wondering if anyone else has come up with a solution to this problem.

    Thanks

    Karen

     Sub ReAssignQueryNames()
       Dim wsh As Worksheet, qt As QueryTable, Name As Name, s As String
       
       On Error Resume Next
       Debug.Print "------Begin ReAssignQueryName-------------"
       For Each wsh In ThisWorkbook.Worksheets
          For Each qt In wsh.QueryTables
             Set Name = wsh.Names(Strings.Replace(qt.Name, " ", "_"))
             s = "sheet " & wsh.Name & ", query: " & qt.Name
             If Err <> 0 Then
                s = "Could not match name for " & s
                Err.Clear
             Else
                wsh.Names.Add Name:=Name.Name, RefersTo:="='" & wsh.Name & "'!" & Name.RefersToRange.Address
                If Err <> 0 Then
                   s = "Could not reset name for " & s
                   Err.Clear
                Else
                   s = "Reset name for " & s
                End If
             End If
             Debug.Print s
          Next
       Next
       Debug.Print "------End ReAssignQueryName--------"
       On Error GoTo 0
    End Sub
    Last edited by VBA Noob; 10-26-2007 at 03:33 AM.

  2. #2
    Registered User
    Join Date
    03-20-2007
    Posts
    2
    Hi Karen,

    I experience this problem ALL the time (well quite often) and yours is the first post I have read on any messageboard that confirms it- I had always assumed it was something I was doing wrong!

    Its caught me out big time in the past as the query has been deleted (unnoticed) and the spreadsheet saved so that the next time it is called up the data is unchanged and everybody assumes my spreadsheet is crap!

    My solution is somewhat simplier as I just put a querytables.count in the BeforeSave Event and if this number is not equal to the number of QT expected then I pop up a message box to contact me and don't allow the user to save the file. This causes occasional user frustration but not nearly as much as the file being saved minus the queries!

    I shall watch this thread with interest.

    Regards,

    Pete

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1