Excel VBA - "IF Answer = Problem"

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. :
 
T

Thomas Wieser

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
 
B

Bob Phillips

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)
 
P

Paulw2k

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VbOk not responding 3
Save as CSV 1
form problems 1
Save .xls as .txt In DeskTop 3
hyperlinks 1
Delete row from ListBox with RowSource enabled 2
break link problem 5
Understanding declarations 1

Top