[VBA] Attempting to transform a string into a number

Hello

I would like to know if there is a kind of "Try ... catch" in the VBA. This is to test whether or not a string can be transformed into a number.
What I do, I get the title of the document and get the first 3 characters. Like this: 'ShortName = Left(Part.GetTitle, 3)'

Then I assign it to an integer variable, the problem is that if it's not a number then I have an error, which bothers me a bit.
I tested 'isNumeric', the problem is that it should always be false, because the typename is 'String'.

Thank you!

Hello

In VB, error handling is done with On Error goto

http://silkyroad.developpez.com/VBA/GestionErreurs/

2 Likes

Here is an example of error handling on the transformation of a variable in String format to a variable in Integer format


test_chaine.swp
2 Likes