Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 15th, 2004, 11:13 PM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA wording

I have this code:

With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://chart.yahoo.com/m?a=2&b=01&c=2001&d=2&e=31&f=2004&g=m&s=" & StockTicker, _
        Destination:=Range("A1"))

But the problem is the ActiveSheet part. Is there a way to make it more specific sort of like:

With Worksheets("Stocks").QueryTables.Add(Connection:= _
        "URL;http://chart.yahoo.com/m?a=2&b=01&c=2001&d=2&e=31&f=2004&g=m&s=" & StockTicker, _
        Destination:=Range("A1"))

Of course, if the above worked I wouldn't be asking here :)

Thanks!

 
Old April 16th, 2004, 04:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You could try prefixing with
Code:
ThisWorkbook.Worksheets("Stocks").QueryTables
or alternatively, if this is going to be a static sheet i.e. not something you create on the fly, you could give the sheet in question a 'code' name - you can do this in the properties window in the IDE. Say you name the sheet 'Stocks' you then referr to it like this
Code:
Stocks.QueryTables.Add(Connection:= _
        "URL;http://chart.yahoo.com/m?a=2&b=01&c=2001&d=2&e=31&f=2004&g=m&s=" & StockTicker, _
        Destination:=Range("A1"))

but I've just noticed that the real problem lies with the QueryTables destination range, which is defaulting to the active sheet (a common problem, with recorded macros).
Try this
Code:
With ThisWorkbook.Worksheets("Stocks")
      .QueryTables.Add(Connection:= _
        "URL;http://chart.yahoo.com/m?a=2&b=01&c=2001&d=2&e=31&f=2004&g=m&s=" & StockTicker, _
        Destination:=.Range("A1"))
End with
Chris

There are two secrets to success in this world:
1. Never tell everything you know





Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA help davidbrooks Visual Basic 2008 Essentials 2 March 26th, 2008 07:25 PM
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
New to VBA. Please help me. rupen Access VBA 1 May 27th, 2005 07:54 AM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM
VBA bjackman Access 1 January 7th, 2004 12:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.