normanbox

New Member
Joined
Jul 8, 2015
Messages
46
I'm a novice at VBA and am using the immediate window. I am getting a Run-Time error '1004': Application-defined or object-defined error and I don't know why. I have the following code in my immediate window.

ActiveCell.QueryTable.Connection="URL;http://finance.yahoo.com/q/bs?s=[""BalanceSheets""]&+Balance+Sheet&annual"

I have a similar code, but for the Income Statement which works just fine. I created the code last week and can't seem to find it now, otherwise I would show you.

Any help on why I'm getting the error would be appreciated and also any ideas where code placed in the immediate window is stored would also be helpful.

Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Thanks.

When I eliminate the two double quotes, I then get a "Compile error: Expected: end of statement" which I also can't figure out why I'm getting.
 
Upvote 0
look at the one that works but


strings are deliminated by pairs of "" and joins involve & so " text " & "-" & "more text" works because of how it joins together

yours does this in excel
"URL;No Ticker Symbol - Yahoo! Finance["
"BalanceSheets"
"]
&
+Balance+Sheet&annual"
 
Upvote 0
Whats the actual URL that you are trying to connect to? Is BalanceSheets really a part of the original URL or are you trying to refer to a named range there?
 
Upvote 0
I'm going crazy because I can't find the one that works, otherwise I would. The troubling thing, it's part of the same workbook! I can only find part of connection property, which says, "http://finance.yahoo.com/q/s/is?s=["Ticker"]&+Income+Statement&annual". When I entered the entire code, which I can't find, I was able to point to where the "ticker symbol" lies and the query updated.

I have been trying to follow the example I found at: https://blogs.office.com/2009/07/31/using-parameters-with-web-queries/ which is how I was able to get the Income Statement code to work. In the page it has me complete the following steps:
1.Click any cell in the new table.
2.Open the Visual Basic Editor by hitting the Alt+F11 key.
3.Hit control+g to open the immediate window.
4.Now type the following line:
activecell.QueryTable.Connection=”URL;http://moneycentral.msn.com/companyreport?symbol=[“”Ticker””]”
5.Click Enter to confirm.
6.Close the Visual Basic Editor.

Then it goes on and gives additional instructions, which worked perfectly.

I must be missing something simple to complete the code and find my other code.
 
Last edited:
Upvote 0
V_Malkoti,

The actual URL is: http://finance.yahoo.com/q/bs?s=AAME+Balance+Sheet&annual

However, the ticker is "AAME" and that is updated based on sheet "Data A1".
 
Last edited:
Upvote 0
Try this:

ActiveCell.QueryTable.Connection = "URL;http://http://finance.yahoo.com/q/bs?s=" & [Data!A1] & "+Balance+Sheet&annual"

AAME ticker value will be read from cell A1 of sheet Data.
 
Upvote 0
That is great progress, but the ticker symbol doesn't dynamically update the ticker based on what's in Data!A1. For example, if I update the cell with AAU, it doesn't automatically update the query to that symbol's webpage, whereas I'm able to do that in my Income Statement query.
 
Last edited:
Upvote 0
in this instance Data!A1 is only read when the macro is run

unless you have an on worksheet_change event that monitors Data!A1 and runs the query
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,977
Latest member
dbonilla0331

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top