Excel VBA - "IF Answer = Problem"

  • Thread starter Thread starter Fraggs
  • Start date Start date
F

Fraggs

I'm using the code below to make a msgbox:

Answer = MsgBox("Do you wish to open part one ?", _
vbOKCancel, "My Title")
If Answer = vbCancel Then Exit Sub
If Answer = vbOK Then ActiveWorkbook.FollowHyperlink Address:= _
"Q:\path is here\baook1.xls" _
, NewWindow:=False, AddHistory:=True
Sheets("Mar_04").Select
Range("A1").Select

But it isnt working and I have no idea how to fix this problem. An
helpmwould be greatly appreciated. :
 
Hi,

I'm note quite sure, but I think you have to write the End If statement
every time:

If Answer = vbCancel Then
Exit Sub
End If

If Answer = vbOK Then
ActiveWorkbook.FollowHyperlink Address:= [...]
End If



The better version for this would be:

If Answer = vbCancel Then
Exit Sub
Else
ActiveWorkbook.FollowHyperlink Address:= [...]
End If



Regards, Thomas
 
Fraggs,

It would help if you told us what isn't working. I tested it and it worked
for me.

How did you declare Answer, it should not be a string or range?

Post back more details.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Hi Fraggs

Mimicking your code I had the same problem. Looking in the Excel VBA help
file I noticed the following in
the FollowHyperlink Method:
AddHistory Optional Variant. Not used. Reserved for future use.

I got rid of the AddHistory parameter and everthing was fine.

Do likewise and yours should work too
If Answer = vbOK Then ActiveWorkbook.FollowHyperlink Address:= _
"Q:\path is here\baook1.xls" _
, NewWindow:=False

Regards

Paul
 
Back
Top