Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Setting print area within macro

I have the following macro to select a specific worksheet and print based on
user input of worksheet name:

Sub PrintWS()
Dim ws As Worksheet
Dim sName$

On Error GoTo ErrorInPrintWS
sName = InputBox("Enter worksheet name", "Print")
If sName < "" Then
Set ws = Worksheets(sName)
ws.PrintOut
End If

Exit Sub
ErrorInPrintWS:
Exit Sub
End Sub

I tried to alter it as follows to define a specific print range but was not
successful.

Sub PrintDeptArea()
Dim ws As Worksheet
Dim sName$

On Error GoTo ErrorInPrintWS
sName = InputBox("Enter worksheet name", "Print")
If sName < "" Then
Set ws = Worksheets(sName)
ActiveSheet.PageSetup.PrintArea = "$A$9:$R$74"
ws.PrintOut
End If

Exit Sub
ErrorInPrintWS:
Exit Sub
End Sub

Can anyone help?
Thanks,
Tim


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Setting print area within macro

Sub PrintDeptArea()
Dim ws As Worksheet
Dim sName$

On Error GoTo ErrorInPrintWS
sName = InputBox("Enter worksheet name", "Print")
If sName < "" Then
Set ws = Worksheets(sName)
ws.PageSetup.PrintArea = "'" & ws.Name & "'!$A$9:$R$74"
' ws.PrintOut
End If

Exit Sub
ErrorInPrintWS:
Exit Sub
End Sub

--
Regards,
Tom Ogilvy


"TimMalone" wrote in message
...
I have the following macro to select a specific worksheet and print based

on
user input of worksheet name:

Sub PrintWS()
Dim ws As Worksheet
Dim sName$

On Error GoTo ErrorInPrintWS
sName = InputBox("Enter worksheet name", "Print")
If sName < "" Then
Set ws = Worksheets(sName)
ws.PrintOut
End If

Exit Sub
ErrorInPrintWS:
Exit Sub
End Sub

I tried to alter it as follows to define a specific print range but was

not
successful.

Sub PrintDeptArea()
Dim ws As Worksheet
Dim sName$

On Error GoTo ErrorInPrintWS
sName = InputBox("Enter worksheet name", "Print")
If sName < "" Then
Set ws = Worksheets(sName)
ActiveSheet.PageSetup.PrintArea = "$A$9:$R$74"
ws.PrintOut
End If

Exit Sub
ErrorInPrintWS:
Exit Sub
End Sub

Can anyone help?
Thanks,
Tim




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Setting print area within macro

Tom,
Thanks! I works like a charm.

"TimMalone" wrote:

I have the following macro to select a specific worksheet and print based on
user input of worksheet name:

Sub PrintWS()
Dim ws As Worksheet
Dim sName$

On Error GoTo ErrorInPrintWS
sName = InputBox("Enter worksheet name", "Print")
If sName < "" Then
Set ws = Worksheets(sName)
ws.PrintOut
End If

Exit Sub
ErrorInPrintWS:
Exit Sub
End Sub

I tried to alter it as follows to define a specific print range but was not
successful.

Sub PrintDeptArea()
Dim ws As Worksheet
Dim sName$

On Error GoTo ErrorInPrintWS
sName = InputBox("Enter worksheet name", "Print")
If sName < "" Then
Set ws = Worksheets(sName)
ActiveSheet.PageSetup.PrintArea = "$A$9:$R$74"
ws.PrintOut
End If

Exit Sub
ErrorInPrintWS:
Exit Sub
End Sub

Can anyone help?
Thanks,
Tim


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
setting the print area from a macro Joe Farruggio Excel Worksheet Functions 10 November 25th 06 01:10 AM
Macro script for setting Print Area JB2010 Excel Discussion (Misc queries) 3 January 12th 06 06:05 PM
Setting the Print Area in a macro. Dick Snow Excel Programming 2 July 22nd 05 02:30 PM
Setting Print Area dolppm Excel Programming 2 March 8th 05 09:35 PM
Setting print area Don Guillett[_4_] Excel Programming 0 September 4th 03 02:14 PM


All times are GMT +1. The time now is 06:08 PM.

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"