1

I've been reading some Microsoft documentation about error handling in VBA and they recommend to include this code in your startup routines to set the appropriate error handling level:

Sub SafeStart()
  Application.SetOption "Error Trapping", 1
End Sub

This basically changes this setting inside Tools > Options:

enter image description here

I changed the setting manually and it works great. However I haven't been able to change it through code since VBA throws the error "Object doesn't support this property or method". Any idea how to set this option in VBA or why it's throwing this error?

Thanks

https://msdn.microsoft.com/en-us/library/Ee358847(v=office.12).aspx

Community
  • 1
  • 1
lisovaccaro
  • 32,502
  • 98
  • 258
  • 410
  • 1
    i think you are using wrong vversion – Raghavendra Aug 13 '15 at 12:01
  • I'm using VBA 7.1. Maybe there is a new way to do it in this version? – lisovaccaro Aug 13 '15 at 12:02
  • use On Error for handling – Raghavendra Aug 13 '15 at 12:04
  • try this http://stackoverflow.com/questions/1038006/good-patterns-for-vba-error-handling/24187560#24187560 – Raghavendra Aug 13 '15 at 12:05
  • I use On Error but I don't want to add it to every method and function of my code. I'd rather change the setting, I just added a screenshot of the setting I want to change. It's inside Tools > Options > General – lisovaccaro Aug 13 '15 at 12:07
  • raghavendra is correct. "Error Trapping" is no longer a property of setoptions after Access 2007. I think VBA 7 came with Office 2010. Also, I see on that same documentation they talk about "On Error Resume Next". My advice to you is to almost NEVER use that. You should understand why errors occur and code for them. – MatthewD Aug 13 '15 at 12:59
  • Hi @MatthewD the thing is I can't even call the SetOptions method. The application object doesn't have it. Is that normal? – lisovaccaro Aug 13 '15 at 13:02
  • 1
    Yes, it seems they have taken that method out. Not sure why. In general I don't use error handling unless I know that a particular sub has potential for errors and I want to handle it to let the user know. https://msdn.microsoft.com/en-us/library/office/ff192651(v=office.14).aspx – MatthewD Aug 13 '15 at 13:12
  • @lisovaccaro yes it normally because it is not exists so use alternate solutions manually handle the errors – Raghavendra Aug 13 '15 at 13:39
  • above this one use resume next Application.SetOption "Error Trapping", 1 problem solve :) – Raghavendra Aug 13 '15 at 13:41

1 Answers1

3

Application.SetOption and Application.GetOption are not available in Excel, they're only available in Access. (The MSDN article you linked to includes "Applies to: Microsoft Office Access 2007".)

p.s. In reference to the comments on your question, I just confirmed that the options are still there and operational in Access 2013 so I'm guessing those commenters might have been getting mixed up between Access and Excel.

Benjamin Warren
  • 529
  • 4
  • 5