macro fails when clipborrd is empty.

  • Thread starter Thread starter Tonso
  • Start date Start date
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
 
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.
 
Back
Top