Open browser, copy text

wut

Banned
Joined
Dec 13, 2010
Messages
229
I use this code to open my browser window.

Code:
Dim Browser As Object
Set Browser = CreateObject("InternetExplorer.Application")
link = "http://link.com"
Browser.navigate (link)
Browser.Visible = True

How do I select the contents of the webpage and copy them?

Is there a list of commands like that anywhere that can be used with other applications? I tried sendkeys and it wouldn't work. I found something about this the other day on ozgrid but I can't find it again.
 
Well this worked for me.
Code:
Option Explicit
 
Sub OpenMedia_Click()
Dim Browser As Object
Dim link As String
 
    Set Browser = CreateObject("InternetExplorer.Application")

    link = "Your link here"
 
    Browser.Navigate (link)

    Browser.Visible = True

    While Browser.Busy And Browser.ReadyState <> 4: DoEvents: Wend

    Browser.ExecWB 17, 0

    Browser.ExecWB 12, 0
    
    Browser.Quit
    
    With ThisWorkbook.Sheets("test")
        .Range("A1").PasteSpecial xlPasteAll
        Application.Goto .Range("A1"), True
    End With
    
End Sub
Though I must admit the results were a bit garbled, which is why I asked what you were trying to do.

If you are looking to get specific data from a web page there are other ways to do it.

Like you said earlier you have an object, IE.

Inside that object is another object, the web page itself, which has a DOM.

Using the DOM (Document Object Model, I think) you can do these sort of things:

- extract data, eg tables, from the page
- enter/select data in the page, eg put values in textboxes, select an item from a combobox
- etc
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
The more information I give you the more complicated this is going to get.

I need to understand why this is locking up if I'm going to get anywhere.

This code fails at "range().select". But "range()select" runs just fine on its own. How can that be?

Code:
sub [COLOR=red][B]fails[/B][/COLOR]()
 
Dim Browser As Object
 
Set Browser = CreateObject("InternetExplorer.Application")
link = "http://www.google.com" 
 
Browser.Navigate (link)
Browser.Visible = True
 
While Browser.Busy And Browser.ReadyState <> 4: DoEvents: Wend
 
Browser.ExecWB 17, 0
Browser.ExecWB 12, 0
Browser.Quit
 
ThisWorkbook.Activate
Sheets("Test").Activate
Range("A1:Z1000").Select
Selection.Clear
 
end sub


Code:
sub [B][COLOR=darkgreen]succeeds[/COLOR][/B]()
 
Range("A1:Z1000").Select
 
end sub
 
Last edited:
Upvote 0
Forget it.

Sheets("test").UsedRange.ClearContents works fine, although I still won't be able to do what I want to do, and I still haven't gained any knowledge that will prevent this problem from cropping up in the future.
 
Upvote 0
wut

What is it you want to do?

This is just not needed.
Code:
ThisWorkbook.Activate
Sheets("Test").Activate
Range("A1:Z1000").Select
Selection.Clear
It can be done in 1 line.
Code:
ThisWorkbook.Sheets("Test").Range("A1:Z1000").Clear
No need for Select/Activate/Selection - they just aren't needed and not only that they cause problems.
 
Upvote 0
I've noticed. I need to understand why... post #22.

How can it be the case that "range().select" runs just fine on its own, then fails inside the other procedure?
 
Last edited:
Upvote 0
To be honest I don't fully understand myself.:)

I think, and I stress think, it's because even though you've activated/selected workbooks/worksheets in the code Excel/VBA still doesn't see those as being the
active objects or sees other other objects as being active.

So, when you try something like Range("A1:A10").Select on it's own, without references, Excel/VBA get's in a 'tizzy' and throws out an error.

That probably makes no sense, and I could be totally wrong, but that's what happens and one way to stop it happening is to use references and not Select/Activate.:)
 
Upvote 0
That's the weird thing.

{Sheets("test").Range("A1").Select} works just fine on its own. That also fails when it's put into the block up above.

That's why I had that part of the code split into so many separate lines... I wanted to really be able to step through it and identify where the problem was.

I'll try your suggestion out and see how it goes. Thanks.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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