![]() |
Paste method of worksheet class failed
Sub MyTask()
Dim ie As Object Dim c As Long Set objWSS = CreateObject("WScript.Shell") Set ie = CreateObject("InternetExplorer.Application") With ie .Visible = True .navigate "http://MyPage" Do While .ReadyState < 4: DoEvents: Loop '** Above goes to my website With .Document.Forms(0) .UserName.Value = "MyUsername" .Password.Value = "MyPassword" .Action.Click End With '** Above logs in to my website While c <= 9999999 c = c + 1 Wend c = 1 '** Above waits till username and password is authenticated Do While .ReadyState < 4: DoEvents: Loop With ie .navigate "http://MyPage/MyAspPage" Do While .ReadyState < 4: DoEvents: Loop '** Above pulls up the page that I want in the same IE window I am doing this because I have to be logged in. End With ie.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT, Null, Null ie.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT, Null, Null Range("A1").Select ActiveSheet.Paste Range("A1").Select '** Above puts the data in clipboard (SELECTALL) and paste it in A1 End With ie.Quit Set ie = Nothing End Sub I get an error: Run-time error '1004': Paste method of Worksheet class failed Note: For the above code to work, CHECK Microsoft Internet Controls from Tools-References in the VBA window Sometimes it works and sometimes it gives me error. I do not understand why is it acting so funny |
Paste method of worksheet class failed
It is possible that the failure results from the clipboard being empty. Can
you check the clipboard staus before attempting the paste? -- Gary''s Student "Maxi" wrote: Sub MyTask() Dim ie As Object Dim c As Long Set objWSS = CreateObject("WScript.Shell") Set ie = CreateObject("InternetExplorer.Application") With ie .Visible = True .navigate "http://MyPage" Do While .ReadyState < 4: DoEvents: Loop '** Above goes to my website With .Document.Forms(0) .UserName.Value = "MyUsername" .Password.Value = "MyPassword" .Action.Click End With '** Above logs in to my website While c <= 9999999 c = c + 1 Wend c = 1 '** Above waits till username and password is authenticated Do While .ReadyState < 4: DoEvents: Loop With ie .navigate "http://MyPage/MyAspPage" Do While .ReadyState < 4: DoEvents: Loop '** Above pulls up the page that I want in the same IE window I am doing this because I have to be logged in. End With ie.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT, Null, Null ie.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT, Null, Null Range("A1").Select ActiveSheet.Paste Range("A1").Select '** Above puts the data in clipboard (SELECTALL) and paste it in A1 End With ie.Quit Set ie = Nothing End Sub I get an error: Run-time error '1004': Paste method of Worksheet class failed Note: For the above code to work, CHECK Microsoft Internet Controls from Tools-References in the VBA window Sometimes it works and sometimes it gives me error. I do not understand why is it acting so funny |
Paste method of worksheet class failed
That is exactly what I was thinking of
But sometimes it works which proves that data is copied to the clipboard. Therefore the only possibility left out is sometimes the data is copied to the clipboard and sometimes not becuase of which ActiveSheet.Paste does not work. I am not sure how to tackle this issue. How do you check the status of the clipboard? What would be the syntax? |
All times are GMT +1. The time now is 09:50 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com