Excel VBA - Want to avoid crash after Cancel link

  Heefie 19:40 26 Nov 04
Locked

Apologies if this is very basic, I'm very new to VBA & this is so different to the sort of programming (COBOL Mainframe) that I'm used to !!!

I'm running Win2k Professional, version 5.0.2195 SP4 Build 2195 if it's relevant !!!

In an EXCEL (2000, 9.0.6926 SP-3) spreadsheet I have added a button to link to and open a HLP file, the CLICK code is as follows :

Private Sub KickaboutHelp_Click()
ActiveWorkbook.FollowHyperlink "C:\MyFiles\MyDoc.hlp"
End Sub

This works, but throws up a Microsoft Office Window that says :

"Opening C:\MyFiles\MyDoc.hlp

Some files can contain viruses or otherwise be harmful to your computer.

It is important to be certain that this file is from a trustworthy source.

Would you like to open this file ?

===> OK === ===> Cancel ==="

I have Tools / Macro / Security set to "LOW" and have checked Trust ALL installed Add-ins and templates", so I don't understand why I am getting this question anyway, so if somebody can tell me how to avoid this problem then that's perfect, the next bit will never occur !!!

However, what's happening is that if I click on OK, my HLP file opens as required, but if I click on CANCEL it crashes with the following :

Run-time error '287'
Application-defined or object-defined error

I won't often click on CANCEL, but if I do, I don't want it to crash, obviously ... all help very appreciated !!!

  Simsy 20:26 26 Nov 04

but to avoid seeing the message you could try;

Application.DisplayAlerts = False

before the line

ActiveWorkbook.FollowHyperlink "C:\MyFiles\MyDoc.hlp"

and the add after that line

Application.DisplayAlerts = True


I'm clutching at straws a bit with it! (VoG will be along soon to put us right!!)

Good luck,

Regards,

Simsy

  Heefie 20:44 26 Nov 04

Thanks for trying, but no cigar <g> !!!

  VoG II 21:23 26 Nov 04

I don't understand why you are the security warning, or an error for that matter.

To stop the crash enter the following line immediately before the code:

On Error Resume Next

Then after the call

On Error Goto 0

It has been a long day --- I'll give some more thought to the security error when I'm more awake.

  VoG II 22:01 26 Nov 04

click here

Try avoiding the hyperlink statement. Instead use something like:

Application.Help HelpFile:="C:\MyFiles\MyDoc.hlp"

  Heefie 23:12 26 Nov 04

... and it prevents the crash, excellent, thanks ... I'll try the other in a mo ...

As it happens, I have hyperlinks in this spreadsheet that run a couple of VB .exe programs & they ask the exact same question.

If I could get rid of it I would be a happy chappy ...

  Heefie 09:22 27 Nov 04

You're a star, thanks for that, it works perfectly, now I know where to come for all my VBA questions, and believe me, I have plenty <g> !!!!!

This thread is now locked and can not be replied to.

How to get Windows 10 for free | How to install Windows 10: There is still a way to avoid paying…

1995-2015: How technology has changed the world in 20 years

Hands-on with the Star Wars fighting drones you can fly yourself

15 macOS Sierra tips | How to use macOS Sierra: Secret tricks and best new features in Apple's new…