Open browser, go to website and copy all

USAMax

Well-known Member
Joined
May 31, 2006
Messages
843
Office Version
  1. 365
Platform
  1. Windows
Does anyone have a basic routine to open a web browser, go to the web site and copy all of the information?

I have four sites that are always being updated and I need to check information against the lists on these sites.

This is what I have found and modified but does not work:

Rich (BB code):
Dim objIExplorer As InternetExplorer
Public Sub Main()
    'Reference set for: 'Microsoft Internet Controls'
    
    Set objIExplorer = CreateObject("InternetExplorer.Application")
    
    'Disable pop-up messages
    objIExplorer.Silent = True
    
    objIExplorer.Navigate "www.google.com"
    Do While objIExplorer.Busy Or Not objIExplorer.ReadyState = 4: DoEvents: Loop
    'objIExplorer.Document.getElementById("q").Value = "Hi"      'Set the value in the Inputbox
    SendKeys "^a"                                           'Select all
    SendKeys "^c"                                           'Copy
    SendKeys "%{F4}", True                            'Exit without saving

    
End Sub

Right from the beginning I get a, "Microsoft Visual Basic for Applications" error that reads: Compile error: User-defined type not defined

After clicking OK it highlights, "objIExplorer As InternetExplorer" on the first line of the code.

I have:
Excel 2010
Windows 8
Internet Explorer 11 (Version: 11.0.9600.16521) I need this to work on as many versions of Internet Explorer as possible.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I haven't looked at your code, but from the error you describe it may be that you have not set references to:
Microsoft HTML Object Library and
Microsoft Internet Controls.

To set them open the VBE>Tools>References and check the box for each, then run the code.
 
Upvote 0
I found a way to do it but I have to find an easy way to remove all Hyperlinks before refreshing the page.

Code:
Sub Test(cSite as string)
Dim Browser As Object
    Const cc As Integer = 1                                 'Current Column
    cr = 1                                                  'Current Row
    
    Set Browser = CreateObject("InternetExplorer.Application")
    link = cSite
    Browser.navigate (link)
    Browser.Visible = True
    Application.Wait Now + TimeValue("00:00:03")
    SendKeys "^a"                                           ‘Select all
    SendKeys "^c"                                           'Copy
    Application.Wait Now + TimeValue("00:00:01")
    SendKeys "%{F4}", True                                  'Exit without saving
    Windows(ActiveWorkbook.Name).Activate
    
    ActiveSheet.Paste
    Call delpics
    
End Sub

Function delpics()
'TO DELETE ALL PICTURES IN WORKSHEET
    For Each Pic In ActiveSheet.Pictures
        Pic.Delete
    Next Pic
End Function
 
Upvote 0

Forum statistics

Threads
1,215,208
Messages
6,123,642
Members
449,111
Latest member
ghennedy

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