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.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
depending on what you want a web query might do it, but there are other methods that have appeared recently on the board also. try a search for web query as a first port of call
 
Upvote 0
Wut

What is it you are trying to do?

If you are trying to get data from a webpage, why not use a web query?
 
Upvote 0
diddi seems to agree. Can you get me started with that?

I would like to use this method if I can. I don't know why sendkeys isn't working, but since "browser" is an object, shouldn't I just be able to do this...?

Code:
browser.selectall
browser.copy

But it doesn't support the property or method. I don't know where to go from here.
 
Upvote 0
Hello wut,

This macro will copy the full web page to the clipboard.
Code:
Sub CopyWebPage()

  Dim ieApp As Object
  Dim URL As String
  
    URL = "http://www.mrexcel.com/"
    
    Set ieApp = CreateObject("InternetExplorer.Application")
    
      ieApp.Navigate URL
      ieApp.Visible = True
      
      While ieApp.Busy And ieApp.ReadyState <> 4: DoEvents: Wend
      
     'Select All
      ieApp.ExecWB 17, 0
      
     'Copy to the clipboard
      ieApp.ExecWB 12, 0
      
   ieApp.Quit
    
End Sub
Sincerely,
Leith Ross
 
Upvote 0
Thanks diddi, I'll check that thread out when I have more time to put into this just to see where that went.

Leith: I appreciate your help, although I can't help but feel a little disgusted. It's seems like there's always some command that I couldn't possibly have found or thought of that's critical to the solution of a given issue.

Would you explain some stuff so I understand the code better?

First, where can I find a list of those "ExecWB" commands?
 
Upvote 0
Why are you 'disgusted'?

I really don't understand that.

Why should there be a simple 'command' to do what you want?
 
Upvote 0
Hello wut,


  1. You will need to set a reference in your VBA project to Microsoft Internet Controls.
  2. In the Project/Library down, select SHDocVw.
  3. In the Classes list, select OLECMDID enumeration constants. This will list the available commands you can use with ExecWB method.

Sincerely,
Leith Ross
 
Upvote 0
Thanks Leith. I'll check it out.

I've had this fail before, and it's failing now, but I don't understand why. Can you give me an idea about it?

Code:
Private Sub OpenMedia_Click()
Dim Browser As Object
Set Browser = CreateObject("InternetExplorer.Application")
link = [I][COLOR=red]Removed Link - Moderator[/COLOR][/I]
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").Select
'Sheets("test").Paste
End Sub

It fails at "Range("A1").Select", saying the method of the class failed. But the method should be fine. What's up?
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
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