Catching macro error

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Lazy-legs
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Catching macro error

Post by Lazy-legs »

Hello,

I have a simple macro that opens a browser specified in a Global variable:

Code: Select all

Global Const DefaultWindowsBrowser="C:\Program Files\Mozilla Firefox\firefox.exe"
Shell(DefaultWindowsBrowser,1, LookupWord.String)
As you can see, the path to the browser is hard-wired, so if you use other browser than Firefox, or the browser is installed in a different location, the macro won't work. How do I "catch" the error, so I can make do macro something useful if the browser is not found in the specified path? I hope my question makes sense.

Kind regards,
Dmitri
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Catching macro error

Post by JohnV »

Code: Select all

Global Const DefaultWindowsBrowser="c:\Program Files\Mozilla Firefox\firefox.exe"

Sub FF
On Error goto EH
Shell(DefaultWindowsBrowser,1,"String")
End
EH:
MsgBox "Error # " & err & ": " & error$ + chr(13) + "In line : " + Erl
End sub
My Firefox is located where you have it. If I change the drive I will get error # 53 - FIle not found. If I leave it alone and use LookupWord.String I get a Variable not set error. If I use "String" then Firefox opens http://www.String.com .
User avatar
Lazy-legs
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: Catching macro error

Post by Lazy-legs »

Thank you, JohnV, for saving my day. Again. :-)

Kind regards,
Dmitri
Post Reply