How to put in a warning?

T

Teak

How do I put in a warning in the macro below, like:
"Is the printer ready?" and pause for an answer.
If "yes", macro continues
If "No", abort.

Thank you.

Sub PrintWithPgNumInTitleRow()
Dim NumPages As Long, Pg As Long
NumPages = ExecuteExcel4Macro("Get.document(50)")
ActiveSheet.Range("TotalPages").Value = NumPages
For Pg = 1 To NumPages
With ActiveSheet
.Range("PageNum").Value = Pg
.PrintOut from:=Pg, to:=Pg
End With
Next Pg
End Sub
 
D

Dave Peterson

Dim Resp as long

resp = msgbox(prompt:="Really print?", buttons:=vbyesno)
if resp = vbno then
exit sub
end if

Right near the top of your code??
 
T

Tushar Mehta

Use something like:

If MsgBox("Is the printer ready?", vbYesNo) = vbNo Then
MsgBox "OK. Nothing will be printed"
Exit Sub
End If

For more, check XL VBA help for MsgBox.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Business solutions leveraging technology
Microsoft Most Valuable Professional (MVP) 2000-2004
 
G

Guest

Another solution is to put the printer dialog for the user to determine what happend next--not easy to determine if the printer is ready unless it is next to the PC

Application.Dialogs(xlDialogPrint).Show

If this returns true, the user clicked OK i.e. print else the return value is false i.e. the user clicked Cancel. In adition to this, the user can
select the target printer (why always use the default?),
specify the number of copies etc.
 
T

Tushar Mehta

If you have the appropriate software (VB or the developer version of
Office XP or later), you can create a COM add-in. Of course, it will
only work with Office 2000 or later.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Business solutions leveraging technology
Microsoft Most Valuable Professional (MVP) 2000-2004
 

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