Macro copying website

Max_hugo

New Member
Joined
May 3, 2020
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hi, I am currently working on a macro that would open links to pages and then after opening the website would select everything and copy to Excel, e.g. to a page sheet. Here is my macro:

VBA Code:
Sub www()
    Dim mmnt!
    Dim strUrl$
    Dim ie As Object
    strUrl = "http:"
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.navigate strUrl
    While (ie.Busy Or ie.readyState <> 4): DoEvents: Wend
    mmnt = Timer: While Timer - mmnt < 2: DoEvents: Wend
    ie.ExecWB 17, 0
    ie.ExecWB 12, 2
    Range("A1").Select
    ActiveSheet.PasteSpecial Format:="HTML", link:=False, NoHTMLFormatting:=True
    ie.Quit
    Set ie = Nothing
End Sub

Unfortunately, the macro does not work on some internal pages. The problem occurs after successfully starting Internet Explorer and loading the html page immediately receives the error message:

VBA Code:
Run-time error - 2147467259 (80004005)
While (ie.Busy Or ie.READYSTATE <> 4): DoEvents: Wend

I have a question how to deal with it? How to improve the macro?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
In the VBA editor, click Tools -> References and tick Microsoft Internet Controls. Then replace these lines:

VBA Code:
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
with:
VBA Code:
    Dim IE As InternetExplorerMedium
    Set IE = New InternetExplorerMedium
 
Upvote 0
I am receiving a message after the change
VBA Code:
run-time error '1004' The PasteSpecal method from the Range class failed

[U]The macro has stopped on:[/U]

ActiveSheet.PasteSpecial Format:="HTML", link:=False, NoHTMLFormatting:=True
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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