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
 
If I understand correctly you were providing the value of ticker every time you ran the code from Immediate window, so that's not exactly dynamic. A statement that you write in Immediate window is a one-time command - it doesn't permanently bind to the file.

Now as mole999 suggested you can place this statement in Worksheet_Change event of Data sheet and any change in the sheet will cause the event code to fire.
In case you didn't know how to do that, here are the steps:
1. Open VBA window.
2. Open Project Explorer if not open (View -> Project Explorer; then you should see a workbook-worksheets tree structure in a pane)
3. Double click on icon on Data sheet to open its module.
4. In the two drop-down visible above code window, choose Worksheet and Change.
5. In the subroutine container that is autogenerated, place the line of code.

Now if the ActiveCell that you need to refresh every time is in a different sheet, replace it with complete qualifier.

Sheets("SheetName").Range("B2").QueryTable.Connection = "URL;http://http://finance.yahoo.com/q/bs?s=" & [Data!A1] & "+Balance+Sheet&annual"
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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