Copying webpage from IE not working

XLSM Belgium

New Member
Joined
Mar 31, 2017
Messages
9
Hi,

I modified a code snippet from the internet to work for my needs, but the code keeps giving errors.

The code is this:

Code:
Option Explicit

Private Sub Berekenen_Click()
    Dim IE As Object

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate ThisWorkbook.Sheets("terugverdientijd").Range("L13").Value
        While IE.busy
            DoEvents
        Wend


    
    Sheets("terugverdientijd").Range("L14:L66") = ""
    IE.ExecWB 17, 0 '// SelectAll
    IE.ExecWB 12, 2 '// Copy selection
    Sheets("terugverdientijd").Range("L14").Select
    Sheets("terugverdientijd").PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False
    Range("A1").Select
    
    IE.Quit
    Set IE = Nothing


End Sub

Basically in cell L13 a URL is formed with some parameters from the sheet.
Example URL is this: http://users.skynet.be/betberge/pvd...ff=-0.48&az2=0&roof2=0&peakw2=0&temp_coeff2=0

This URL opens in IE, everything is selected (and I assume copied), but then I get a error 1004 on pastespecial.

I have no idea why.

Sometimes it randomly does work (like 10% of the time)...

Also, there is some text in a flash box (in the example url it's this: )
Donderdag, 15 juni 2017
Zonsopgang: 05:32, Hoogste zonnestand: 62.4° om 13:46, Zonsondergang: 22:01
Theoretisch berekende clear-sky opbrengst: 29727 Wh (6.3 Wh/Wp)
Max clear-sky vermogen: 3803 Watt om 11:30

This never gets copied over (presumably because of the flash thingy), and I would really love to have that information too...

Any ideas on these 2 problems?
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
First Problem:

Code:
While IE.busy Or IE.readyState <> 4
            DoEvents
        Wend
        Application.Wait (Now() + TimeValue("0:0:01"))
 
Upvote 0
First problem solved, I implemented the change NMa91 suggested, and changed the pastespecial to html.

Code:
Option Explicit

Private Sub Berekenen_Click()
    Dim IE As Object


    Set IE = CreateObject("InternetExplorer.Application")
    'IE.Visible = True
    IE.Navigate ThisWorkbook.Sheets("terugverdientijd").Range("L13").Value
        While IE.busy Or IE.readyState <> 4
            DoEvents
        Wend
        Application.Wait (Now() + TimeValue("0:0:01"))


    
    Sheets("terugverdientijd").Range("L14:Q40") = ""
    IE.ExecWB 17, 0 '// SelectAll
    IE.ExecWB 12, 2 '// Copy selection
    Sheets("terugverdientijd").Range("L14").Select
    ActiveSheet.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
    
    IE.Quit
    Set IE = Nothing
    Range("A1").Select
End Sub

Works ok now.

Any idea on how to get the text from the flash graph?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
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