+ Reply to Thread
Results 1 to 5 of 5

Finding Queries in code

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Finding Queries in code

    I want to be able to use code such as
    Please Login or Register  to view this content.
    in a sub routine so that any one of several queries can be deleted.

    How do I find the queries in my workbook using code and how should I make the reference to it in the sub routine
    John

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Finding Queries in code

    Maybe you can adapt this code which deletes all queries:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Finding Queries in code

    Chippy
    Thanks for your suggestion which will be a good basis for what I want. I will try and then let you know how I got on.
    John

  4. #4
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Finding Queries in code

    Chippy
    I made a small modification to your code
    Please Login or Register  to view this content.
    But got an error message on lo.QueryTable.Delete (application or Object defined error)
    I got all the sheet names to print outbwhilst working up to the code so I think the loops are working.
    John

  5. #5
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Finding Queries in code

    Hi John

    Not all ListObjects will necessarily have a QueryTable so it would be worth your while checking that the QueryTable property returns a QT first:

    Please Login or Register  to view this content.

+ 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