Catching macro error

Creating a macro - Writing a Script - Using the API

Catching macro error

Postby Lazy-legs » Mon Feb 25, 2008 7:22 pm

Hello,

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

Code: Select all   Expand viewCollapse view
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
User avatar
Lazy-legs
 
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: Catching macro error

Postby JohnV » Mon Feb 25, 2008 8:23 pm

Code: Select all   Expand viewCollapse view
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 .
JohnV
Volunteer
 
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Catching macro error

Postby Lazy-legs » Mon Feb 25, 2008 8:27 pm

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

Kind regards,
Dmitri
User avatar
Lazy-legs
 
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 10 guests