sujittalukde
07-08-2008, 12:26 AM
I am using the following code to loop through cells and print each page after looping.
If I use Activesheet.printout method it starts printing to default print so I want to show the Print dialog box using this one:
Application.Dialogs(xlDialogPrint).Show
Now where should I put the lineso that if the user
clicks Cancel, Nothing will happen.
Clicks Preview, it will show the preview only for the loop
Clicks Print or OK, it will start printing
In the entire process, Print Dialog has to be shown only once.
Code is:
Sub PrintSlips()
'Application.Dialogs(xlDialogPrint).Show
Sheets("Payslips").Select
rowscnt = Sheets("Employee Pay").UsedRange.Rows.Count
For i = 2 To rowscnt Step 2
emp = Sheets("Employee Pay").Cells(i, 1).Value
emp1 = Sheets("Employee Pay").Cells(i, 1).Offset(1, 0).Value
Sheets("Payslips").Cells(5, 3).Value = emp
Sheets("Payslips").Cells(22, 3).Value = emp1
ActiveSheet.PrintOut
Next i
End Sub
If I use Activesheet.printout method it starts printing to default print so I want to show the Print dialog box using this one:
Application.Dialogs(xlDialogPrint).Show
Now where should I put the lineso that if the user
clicks Cancel, Nothing will happen.
Clicks Preview, it will show the preview only for the loop
Clicks Print or OK, it will start printing
In the entire process, Print Dialog has to be shown only once.
Code is:
Sub PrintSlips()
'Application.Dialogs(xlDialogPrint).Show
Sheets("Payslips").Select
rowscnt = Sheets("Employee Pay").UsedRange.Rows.Count
For i = 2 To rowscnt Step 2
emp = Sheets("Employee Pay").Cells(i, 1).Value
emp1 = Sheets("Employee Pay").Cells(i, 1).Offset(1, 0).Value
Sheets("Payslips").Cells(5, 3).Value = emp
Sheets("Payslips").Cells(22, 3).Value = emp1
ActiveSheet.PrintOut
Next i
End Sub