ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Throw Exception if Clipboard is Empty (https://www.excelbanter.com/excel-programming/435137-throw-exception-if-clipboard-empty.html)

PumaMan

Throw Exception if Clipboard is Empty
 
I have a simple paste action in VBA:

Range("Q2").Select
ActiveSheet.Paste

I'd like to catch and throw an exception if the user's clipboard is empty.
Currently, the user gets the "End - Debug" general exception.

I appreciate any help!


Per Jessen

Throw Exception if Clipboard is Empty
 
Hi

You need to use the error handler:

On Error Resume Next
Range("Q2").Select
ActiveSheet.Paste
If Err.Number = 1004 Then
msg = MsgBox(Err.Description)
End If
Err.Clear


Regards,
Per

"PumaMan" skrev i meddelelsen
...
I have a simple paste action in VBA:

Range("Q2").Select
ActiveSheet.Paste

I'd like to catch and throw an exception if the user's clipboard is empty.
Currently, the user gets the "End - Debug" general exception.

I appreciate any help!



muddan madhu

Throw Exception if Clipboard is Empty
 
Range("Q2").Select
Selection.PasteSpecial xlPasteValues

or

Range("q2").PasteSpecial xlPasteAll


On Oct 19, 6:46*pm, PumaMan wrote:
I have a simple paste action in VBA:

* * Range("Q2").Select
* * ActiveSheet.Paste

I'd like to catch and throw an exception if the user's clipboard is empty.. *
Currently, the user gets the "End - Debug" general exception.

I appreciate any help!



ron

Throw Exception if Clipboard is Empty
 
On Oct 19, 7:46*am, PumaMan wrote:
I have a simple paste action in VBA:

* * Range("Q2").Select
* * ActiveSheet.Paste

I'd like to catch and throw an exception if the user's clipboard is empty.. *
Currently, the user gets the "End - Debug" general exception.

I appreciate any help!


How about something like...

If Application.ClipboardFormats(1) = -1 Then
MsgBox "Clipboard Empty!"
End If

....Ron


All times are GMT +1. The time now is 07:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com