Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Syntax for QueryTable (XL2K)

    What is the correct syntax to refresh an external data query? I have tried
    Sheets("InputData").QueryTable("ReportData").Refre sh
    Which gives me an error message .

    Thanks for any help <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    Peter

  2. #2
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax for QueryTable (XL2K)

    Hi Peter, this from one of my workbooks,

    <pre>ThisWorkbook.Sheets("LABORGUIDE").QueryTables (1).Refresh
    </pre>


    I am not sure that you can refer to the querytable by name. Also, I believe that the sheet will have to be unprotected before it will refresh.

  3. #3
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax for QueryTable (XL2K)

    Thanks for the info <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    I still have not found a way to refer to the query by name and am not sure how to find the number short of trial and error!
    but have found this method which does what I need.

    Worksheets("InputData").Range("c10").QueryTable.Re fresh

    would prefer to refer to query by name though in case I need to modify things!

    Peter

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax for QueryTable (XL2K)

    This works for me:

    sName=activesheet.querytables(1).name
    activesheet.querytables(sName).refresh
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Syntax for QueryTable (XL2K)

    Hi Peter,
    I suspect you need to change
    Sheets("InputData").QueryTable("ReportData").Refre sh
    to read
    Sheets("InputData").QueryTables("ReportData").Refresh
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Syntax for QueryTable (XL2K)

    You can index the QueryTables collection by name. As Rory pointed out, there is the QueryTables collection as opposed to the QueryTable property of a Range. You can determine the name by
    <pre>Sheets("InputData").Range("C10").QueryTable.N ame</pre>

    If you used Excel to create the query, then Excel uses the Name "Query from XXXX", where XXXX is the DataSource, so maybe Sheets("InputData").QueryTables("Query from ReportData").Refresh is what you need. You can also deternine the Query name from the Name box (to the left of the Formula bar). If you have the query with the name "Query from XXXX", then you will have the name Query_from_XXXX in the drop-down. If you used VBA to create the query, then you should use the Name property to give it a useful name. HTH --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  7. #7
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax for QueryTable (XL2K)

    Many Thanks for all of the replies <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Rory had it exactly right! Surprising how much difference a little old "s" can make! Always used to be the punctuation that had me pulling my hair out <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

    I was able to get the query name from the properties sheet for it on the External Data Tool Bar

    Cheers all <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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