Hello fellow Walian.
You use an error handling routine. Your procedure should include an On Error GoTo line that branches your code to a label. Under that label, you include your MsgBox code.
Look under ON Error in HELP. It contains a sub-section called
Elements of Run-time Error Handling
which explains it much better than I can