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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,224,814
Messages
6,181,124
Members
453,021
Latest member
Justyna P

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