Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Using VBA to print a range

Hi to all out there

Hi I was wondering if there is a way of writting VBA code to print a range
in Excel 2003 with a page title this would all happen from a command button.
I could use a macro but I have always been told that VBA is the better way to
go

Thanks in advance

Joel
--
N/A
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using VBA to print a range


Range("A3:C9").PrintOut Copies:=1, Collate:=True

Dave

*** Sent via Developersdex http://www.developersdex.com ***
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Using VBA to print a range


you can sue something like this, just change some of the settings to get what
you want:

Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim rng As Range
Dim lastrow As Long
Set ws = Worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "G").End(xlUp).Row
Application.ScreenUpdating = False
Set rng = ws.Range("A1:G" & lastrow)

With ws
With .PageSetup
.Orientation = xlPortrait
.FooterMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0#)
.LeftMargin = Application.InchesToPoints(0#)
.TopMargin = Application.InchesToPoints(0.9)
.BottomMargin = Application.InchesToPoints(0.45)
.PrintArea = rng.Address
.HeaderMargin = Application.InchesToPoints(0.25)
.CenterHeader = "&B&14Sheet1 Title"
.FitToPagesTall = 1
.FitToPagesWide = 1
.CenterHorizontally = True
End With
.PrintPreview
End With
Application.ScreenUpdating = True
End Sub
--


Gary


"Joel" wrote in message
...
Hi to all out there

Hi I was wondering if there is a way of writting VBA code to print a range
in Excel 2003 with a page title this would all happen from a command button.
I could use a macro but I have always been told that VBA is the better way to
go

Thanks in advance

Joel
--
N/A



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Using VBA to print a range

Thank you very can you please tell me how to print without the colour that is
on the spreadsheet

Joel
--
N/A


"Gary Keramidas" wrote:


you can sue something like this, just change some of the settings to get what
you want:

Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim rng As Range
Dim lastrow As Long
Set ws = Worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "G").End(xlUp).Row
Application.ScreenUpdating = False
Set rng = ws.Range("A1:G" & lastrow)

With ws
With .PageSetup
.Orientation = xlPortrait
.FooterMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0#)
.LeftMargin = Application.InchesToPoints(0#)
.TopMargin = Application.InchesToPoints(0.9)
.BottomMargin = Application.InchesToPoints(0.45)
.PrintArea = rng.Address
.HeaderMargin = Application.InchesToPoints(0.25)
.CenterHeader = "&B&14Sheet1 Title"
.FitToPagesTall = 1
.FitToPagesWide = 1
.CenterHorizontally = True
End With
.PrintPreview
End With
Application.ScreenUpdating = True
End Sub
--


Gary


"Joel" wrote in message
...
Hi to all out there

Hi I was wondering if there is a way of writting VBA code to print a range
in Excel 2003 with a page title this would all happen from a command button.
I could use a macro but I have always been told that VBA is the better way to
go

Thanks in advance

Joel
--
N/A




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Using VBA to print a range

Thank you very can you please tell me how to print without the colour that is
on the spreadsheet

Joel
--
N/A


"Gary Keramidas" wrote:


you can sue something like this, just change some of the settings to get what
you want:

Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim rng As Range
Dim lastrow As Long
Set ws = Worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "G").End(xlUp).Row
Application.ScreenUpdating = False
Set rng = ws.Range("A1:G" & lastrow)

With ws
With .PageSetup
.Orientation = xlPortrait
.FooterMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0#)
.LeftMargin = Application.InchesToPoints(0#)
.TopMargin = Application.InchesToPoints(0.9)
.BottomMargin = Application.InchesToPoints(0.45)
.PrintArea = rng.Address
.HeaderMargin = Application.InchesToPoints(0.25)
.CenterHeader = "&B&14Sheet1 Title"
.FitToPagesTall = 1
.FitToPagesWide = 1
.CenterHorizontally = True
End With
.PrintPreview
End With
Application.ScreenUpdating = True
End Sub
--


Gary


"Joel" wrote in message
...
Hi to all out there

Hi I was wondering if there is a way of writting VBA code to print a range
in Excel 2003 with a page title this would all happen from a command button.
I could use a macro but I have always been told that VBA is the better way to
go

Thanks in advance

Joel
--
N/A






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Using VBA to print a range

Add this line to Gerry's code.

..BlackAndWhite = True

BTW.......Macros are written using VBA so they are the same thing.


Gord Dibben MS Excel MVP


On Sat, 10 Nov 2007 09:17:01 -0800, Joel wrote:

Thank you very can you please tell me how to print without the colour that is
on the spreadsheet

Joel


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
print range won't print Cheri K Excel Discussion (Misc queries) 2 February 25th 10 11:49 PM
Print range Lawman Setting up and Configuration of Excel 3 July 8th 08 01:50 PM
Print Blank Pgs - Preview margins outside print range dsm Excel Discussion (Misc queries) 0 October 25th 06 06:17 PM
Can you get the range reference for each page in a worksheet print range? Crosby Excel Programming 3 April 12th 05 06:06 PM
Excel 2000 VBA - Set Print Range in dynamic range sub_pop[_5_] Excel Programming 2 July 27th 04 08:01 PM


All times are GMT +1. The time now is 02:17 AM.

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

About Us

"It's about Microsoft Excel"