Pop up in excel

V

vandana

Hi...

I have created a macro and one of the command button with marco is to
directly to print. now i need to insert a pop up (logical function) saying "u
sure you want to print" and this should have 2 answers "yes" and "no" if
"yes" continue with printing and if "no" cancel printing.

can any one help me with this please.
 
A

Arvi Laanemets

Hi

Sub MySub
......
continue=MsgBox("Are you sure you want to print it?",vbYesNo)
If Not continue Then Exit Sub
....
End Sub
 
R

Rick Rothstein \(MVP - VB\)

I think you will need the If statement to be this instead...

If continue = vbNo Then Exit Sub

Rick
 
V

vandana

hi.. i am sorry i not very god a macro.. i am still in learning stsge.
could you tel me if i have to paste the below command in macro before are
after this command whichi have for printing.

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

End Sub

it may be a silly question.. tried both ways dint work.. i want a pop up
saying are you sure you want to print?
I think you will need the If statement to be this instead...

If continue = vbNo Then Exit Sub

Rick
[quoted text clipped - 14 lines]
 
R

Rick Rothstein \(MVP - VB\)

You would put the code lines in front so it would look like this...

Sub Your Macro()
'
' Any lines of code you may have above the printout line
'
Continue = MsgBox("Are you sure you want to print it?", vbYesNo)
If Continue = vbNo Then Exit Sub
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub

Not what will happen is the macro you are running will stop running if the
user answers No. If you have other code after this and the printing is only
one of many statements, then you should code it like this...

Sub Your Macro()
'
' Any lines of code you may have above the printout line
'
Continue = MsgBox("Are you sure you want to print it?", vbYesNo)
If Continue = vbYes Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
'
' The rest of your code goes here
'
End Sub


Rick


vandana said:
hi.. i am sorry i not very god a macro.. i am still in learning stsge.
could you tel me if i have to paste the below command in macro before are
after this command whichi have for printing.

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

End Sub

it may be a silly question.. tried both ways dint work.. i want a pop up
saying are you sure you want to print?
I think you will need the If statement to be this instead...

If continue = vbNo Then Exit Sub

Rick
[quoted text clipped - 14 lines]
can any one help me with this please.
 
V

vandana

thanks a lot... it works now.. u guys are the best.
You would put the code lines in front so it would look like this...

Sub Your Macro()
'
' Any lines of code you may have above the printout line
'
Continue = MsgBox("Are you sure you want to print it?", vbYesNo)
If Continue = vbNo Then Exit Sub
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub

Not what will happen is the macro you are running will stop running if the
user answers No. If you have other code after this and the printing is only
one of many statements, then you should code it like this...

Sub Your Macro()
'
' Any lines of code you may have above the printout line
'
Continue = MsgBox("Are you sure you want to print it?", vbYesNo)
If Continue = vbYes Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
'
' The rest of your code goes here
'
End Sub

Rick
hi.. i am sorry i not very god a macro.. i am still in learning stsge.
could you tel me if i have to paste the below command in macro before are
[quoted text clipped - 18 lines]
 

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

Top