Check if clipboard is empty before .PasteSpecial xlPasteValues

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use the sub auto_open() to prevent format to be copied in a copy paste.
With Application
.OnKey "^v", "ValueOnly"
End With

and then this function:
Function ValueOnly()
Selection.PasteSpecial xlPasteValues
End Function

However, the code failes when trying to paste when no cells are highlighted
(you know, after control-C for example). Probably the clipboad is empty which
causes the error. How do I check if the clipboard is empty so I can prevent
the error from happening? Or should I use On Error code to catch such an
event?

Furthermore, is there a way to capture the paste event when used through the
rightclick-menu, edit-menu and button?
(Excel97)
 
Function ValueOnly()
if Application.CutCopyMode = False then
msgbox "Nothing to paste"
else
Selection.PasteSpecial xlPasteValues
End if
End Function
 
in the workbook level selectionchange event, you can check

if application.CutcopyMode = xlCut then
application.cutcopymode = False
msgbox "there will be no cutting in this workbook"
end if
 

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

Back
Top