Macro copying website

Max_hugo

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

VBA Code:
Sub VBA()
    Dim mmnt!
    Dim strUrl$
    Dim IE As InternetExplorerMedium
    strUrl = "http:"
    Set IE = New InternetExplorerMedium
    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 stops after pasting into Excel. I receive the following message. It seems to me that this is because nothing is selected and copied.


run-time error '1004' The PasteSpecal method from the Range class failed
The macro has stopped on:

VBA Code:
ActiveSheet.PasteSpecial Format:="HTML", link:=False, NoHTMLFormatting:=True


I noticed that the above macro works in a situation where quickly after starting InternetExplorer as the page loads, I press any field in the browser. I have a question whether it is possible to improve the macro to load without my interference.
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
6,010
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
What is the URL you are trying to reach.
 

Max_hugo

New Member
Joined
May 3, 2020
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
The URL is the internal page in my work, I can only launch it in my position. I would like to download data for the report from it.
 

Max_hugo

New Member
Joined
May 3, 2020
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
I have a question whether it is not possible after providing the URL to go to the window with the website and then select everything and copy the page?
 

Watch MrExcel Video

Forum statistics

Threads
1,118,852
Messages
5,574,662
Members
412,608
Latest member
Guromir
Top