Yes, it is possible. Likely the code needs to return a value, which subs cannot do, so it might need to be a function. If that function is written to accept a parameter, then that might be better than hard coding the string. However, I get that the code is only for providing an excellent solution (I have tried to learn RegEx but it just doesn't seem to sink in) so well done! As a function:
VBA Code:
Function Example(strIn As String) As Long 'assumes number type of Long is wanted vs anything else
Dim RX As Object
Set RX = CreateObject("VBScript.RegExp")
RX.Global = True
RX.Pattern = "[^0-9 _]"
Example = Split(Trim(RX.Replace(Replace(strIn, "_", " "), "")), " ")(0)
End Function
How it might be called: myVariable = example("ABC 123 981")
or if a return message is needed:
MsgBox Example("ABC 123 981")