macro fails when clipborrd is empty.

T

Tonso

using xl2003, i am copying data from a program, and using a macro to
paste it into excel using text to columns. If i forget to copy the
data, when i run the macro i get "run-time error 1004 - paste method
of worksheet class failed". i would like to add to the macro an IF
statement so when the clipboard is empty, i get a message saying so,
and then i can exit the macro. How do i do this?

Thanks,

Tonso
 
D

Dave Peterson

Maybe you could use something like:

If Application.CutCopyMode = False Then
MsgBox "nothing to paste"
Else
ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteAll
End If

I often let the operation fail, but catch the error.

on error resume next
activesheet.range("A1").pastespecial paste:=xlpasteall
if err.number <> 0 then
err.clear
msgbox "Paste failed"
end if
on error goto 0

Then I can catch any error that causes the paste to fail.
 

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

Top