Hi,
Relatively new to VBA, but having read up on using On Error GoTo commands I cannot understand how the code is not responding when it encounters an error.
The most annoying part is to get to that part of the code it has already correctly been navigated using an On Error statement.
I'm sure it's really just to do with how I've structured/ordered my code.
The error context:
User is copying data from an external source.
In the sub which calls this function, there is a function that checks if the clipboard is empty, so to get to this code VBA has deemed the clipboard is NOT empty.
However the error message only occurs when it seems like nothing has been copied. For example copy an area of data in another instance of excel (which is subsequently surrounded by the black and white moving border).
If you press Esc on the keyboard, the border disappears, and returns to the range just being a highlighted selection.
But stepping through the macro, the clipboard passes the not empty test, then errors when it gets to the red text in the code above.
The error is 'PasteSpecial method of Range class failed'.
Any ideas why the code is not being redirected to the Error Handler when this error occurs?
Relatively new to VBA, but having read up on using On Error GoTo commands I cannot understand how the code is not responding when it encounters an error.
The most annoying part is to get to that part of the code it has already correctly been navigated using an On Error statement.
I'm sure it's really just to do with how I've structured/ordered my code.
Code:
Function PasteUS()
On Error GoTo NextTry
ActiveSheet.PasteSpecial Format:="SYLK", Link:=False, DisplayAsIcon:= _
False
LetsContinue:
Exit Function
NextTry:
On Error GoTo ErrHandler
[COLOR=#ff0000]Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, _[/COLOR]
[COLOR=#ff0000] Transpose:=False[/COLOR]
Application.CutCopyMode = False
Resume LetsContinue
ErrHandler:
MsgBox errstring & " " & Err.Description
Resume LetsContinue
End Function
The error context:
User is copying data from an external source.
In the sub which calls this function, there is a function that checks if the clipboard is empty, so to get to this code VBA has deemed the clipboard is NOT empty.
However the error message only occurs when it seems like nothing has been copied. For example copy an area of data in another instance of excel (which is subsequently surrounded by the black and white moving border).
If you press Esc on the keyboard, the border disappears, and returns to the range just being a highlighted selection.
But stepping through the macro, the clipboard passes the not empty test, then errors when it gets to the red text in the code above.
The error is 'PasteSpecial method of Range class failed'.
Any ideas why the code is not being redirected to the Error Handler when this error occurs?