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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

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