Paste method of worksheet class failed

M

Maxi

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
 
G

Gary''s Student

It is possible that the failure results from the clipboard being empty. Can
you check the clipboard staus before attempting the paste?
 
M

Maxi

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top