Run-time error '91':

jc0r

Board Regular
Joined
Mar 16, 2009
Messages
124
Hi all, i have an error which i can't seem to fix.

I have a module which contains the following code. I am struggling with the procedure CopyData(). It works when the sheet "Raw Data" is active, however, when it is not, i receive the error on the green line highlighted in the code. Making the "Raw Data" sheet active is not an option as i need to work in other sheets whilst this procedure is been called.

Does anyone have any suggestions please

Code:
Sub RefreshURL_Click()link_name = Sheets("Raw Data").Range("F2")
Call Sheets("Raw Data").WebBrowser1.Navigate(link_name)
End Sub
Sub CopyData()
Sheets("Raw Data").WebBrowser1.Refresh
Sheets("Raw Data").WebBrowser1.Copy
[COLOR=#008000]Sheets("Raw Data").Range("E34").Value = Sheets("Raw Data").WebBrowser1.Document.Body.InnerText[/COLOR]
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Ok having not stopped looking for the solution i believe i might know the problem, but no matter what i try, my limited knowledge can't fix it. I think i need to Declare the WebBrowser1 command but I do not know what i need to type or where to type it?
 
Upvote 0
You don't need to declare WebBrowser1, you need to reference it properly.

One thing you could try for that is replacing Sheets("Raw Data") with the codename for the sheet.
 
Upvote 0
When you say codename, do you mean instead of Sheets("Raw Data") put Sheet1? If so i have tried every combination of that and still no joy?
 
Upvote 0
I have tried changing the problem line to the following, but all still give me the run-time error 91 unfortunately

Code:
[COLOR=#008000]Sheet1.Range("E34").Value = Sheet1.WebBrowser1.Document.Body.InnerText[/COLOR][COLOR=#333333] [/COLOR]

Code:
[COLOR=#008000]Sheets("Raw Data").Range("E34").Value = Sheet1.WebBrowser1.Document.Body.InnerText[/COLOR][COLOR=#333333] [/COLOR]

Code:
[COLOR=#008000]Sheet1.Cells (34 , 5).Value = Sheets("Raw Data").WebBrowser1.Document.Body.InnerText[/COLOR][COLOR=#333333] [/COLOR]

Code:
[COLOR=#008000]Sheet1.Cells (34 , 5).Value = Sheet1.WebBrowser1.Document.Body.InnerText[/COLOR][COLOR=#333333] [/COLOR]
 
Upvote 0
Does this work?
Code:
Dim oBrowser As Object
     
    Set oBrowser = Sheet1.WebBrowser1
 
Upvote 0
Thanks for the suggestion Norie but unfortunatly i still receive the error 91.

The code i have now is as follows

Code:
Sub CopyData()Dim oBrowser As Object
Set oBrowser = Sheet1.WebBrowser1
Sheets("Raw Data").WebBrowser1.Refresh
Sheets("Raw Data").WebBrowser1.Copy
Sheets("Raw Data").Value = Sheets("Raw Data").WebBrowser1.Document.Body.InnerText
End Sub

I've tried changing Sheets("Raw Data") to Sheet1 but the results are the same. The code will still only run if the sheet "Raw Data" / "Sheet1" is active. The weird thing, i don't know if this is giving a clue away, but if i run the macro while the Raw Data sheet is active, then switch to another sheet and run the macro, it won't error on the first attempt, be will after?
 
Upvote 0
Ok ive found out the problem, i just dont know how to fix it.

Inside the macro, i have it refresh the browser. When i am on another sheet and run the macro, the refresh will not execute until i select the sheet again. that explains why it runs first time but not after. So i guess the question is, how can i refresh the browser when the sheet is not active?
 
Upvote 0
Can I ask why you are using a WebBrowser control?

If it's to pull data from a specific site/page have considered a web query, or automating IE, or perhaps XMLHTTP.

Automating IE would be kind of similar to working with a WebBrowser control.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

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