VBA PasteSpecial method Worksheet class failed

lionginass

New Member
Joined
Jul 29, 2016
Messages
24
Hello everyone,

I have a code which starts this:

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Private Sub CommandButton1_Click()
Dim destination As Worksheet
Set destination = Worksheets("STATS")
Set myIE = CreateObject("InternetExplorer.Application")
myIE.Navigate "https://www.internetpage.com/lblabla.html"
myIE.Visible = True
Application.Wait (Now + TimeSerial(0, 0, 10))
SendKeys "^a"
SendKeys "^c"
Application.Wait (Now + TimeSerial(0, 0, 3))
destination.Activate
destination.DrawingObjects.Select
Selection.Delete
destination.Cells.Clear
destination.Range("A1").Select
ActiveSheet.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
False, NoHTMLFormatting:=True
On Error Resume Next
myIE.Quit
Set myIE = Nothing
Err.Clear[/FONT]

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
When i click the command button i get an error "PasteSpecial method Worksheet class failed

Debbuger marks yellow this part:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]ActiveSheet.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
False, NoHTMLFormatting:=True

[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Strange thing is when i run this code directly from the developer it runs without errors.
Who has the idea why clicking the button doesnt work here?

One more thing. The code turns off numlock key? Any ideas why?

Thanks[/FONT][FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]

[/FONT]


<strike>
</strike>
[/FONT]
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi Lionginass,

next time when you post code please use cod brackets like shown in red & blue below.

As to your question:
What type of information is being pasted? What do you mean with "running the code directly from the developer"
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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