Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Print specific pages of a Database

I have the following code in my program to allow printing of the
database (size changes frequently).

Public Sub PrintData()
Dim lrow As Range
Dim rc As Integer
Dim ar As Integer
Dim Response As String

Sheets(1).Activate

Set lrow = Sheet1.Range("A" & Rows.Count).End(xlUp)
'
lrow.Activate
'ar = ActiveCell.row
'
'Range(Cells(1, "a"), Cells(ar, "M")).Select ' Selects Print
Area
'
' MsgBox ("Ensure that the Printer is on!")


ActiveSheet.PageSetup.PrintArea = _
ActiveCell.CurrentRegion.Address
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$4"
.PrintTitleColumns = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(0.5)
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLegal
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
Response = MsgBox("Print in Black and White?",
vbYesNo)
If Response = vbYes Then
.BlackAndWhite = True
Else
.BlackAndWhite = False
End If
.Zoom = 100
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Range("A5").Select

Application.ScreenUpdating = True



End Sub


This works beautifully but only prints the entire database, however
there are times that I may only want certain pages to be printed. Any
suggestions on how to do this?

Dooley

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Print specific pages of a Database


You can add the number of the starting page and ending page to your code.

From the Excel VBA help file...
"expression.PrintOut(from, To, Copies, Preview, ActivePrinter, PrintToFile, Collate)"

So your code would look like this to print pages 2 and 3...
ActiveWindow.SelectedSheets.PrintOut From:=2, To:=3, Copies:=1, Collate:=True
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"Dooley"
wrote in message
I have the following code in my program to allow printing of the
database (size changes frequently).

Public Sub PrintData()
Dim lrow As Range
Dim rc As Integer
Dim ar As Integer
Dim Response As String

Sheets(1).Activate

Set lrow = Sheet1.Range("A" & Rows.Count).End(xlUp)
'
lrow.Activate
ActiveSheet.PageSetup.PrintArea = _
ActiveCell.CurrentRegion.Address
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$4"
.PrintTitleColumns = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(0.5)
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLegal
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
Response = MsgBox("Print in Black and White?", vbYesNo)
If Response = vbYes Then
.BlackAndWhite = True
Else
.BlackAndWhite = False
End If
.Zoom = 100
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True '<<<<<
Range("A5").Select
Application.ScreenUpdating = True
End Sub


This works beautifully but only prints the entire database, however
there are times that I may only want certain pages to be printed. Any
suggestions on how to do this?
Dooley

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Print specific pages of a Database

On Jul 21, 9:51 pm, "Jim Cone" wrote:
You can add the number of the starting page and ending page to your code.

From the Excel VBA help file...
"expression.PrintOut(from, To, Copies, Preview, ActivePrinter, PrintToFile, Collate)"

So your code would look like this to print pages 2 and 3...
ActiveWindow.SelectedSheets.PrintOut From:=2, To:=3, Copies:=1, Collate:=True
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



<Snip

Thanks Jim. As usual I didn't read the help file sufficiently to see
the answer was right in front of my face!

Your help is very much appreciated.

Dooley

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
My excel spreadsheet won't print or print preview all the pages? whirlybird Excel Worksheet Functions 2 April 4th 23 10:50 AM
Number of pages in worksheet doesn't match Print Preview pages delru Excel Discussion (Misc queries) 2 May 10th 10 10:08 PM
how do i print pages of pages example (1of3) rene Excel Discussion (Misc queries) 2 May 21st 09 05:03 PM
How to print odd pages and even pages seperately in Excel. DILNAVAS Excel Discussion (Misc queries) 1 June 14th 06 11:45 AM
Can I print only specified pages from a print range such as pages 1,3,4,6 Mel Excel Programming 2 April 12th 05 02:25 PM


All times are GMT +1. The time now is 01:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"