Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Printing / January 2006

Tip: Looking for answers? Try searching our database.

Add'l code for Print command button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PattiP - 03 Jan 2006 15:55 GMT
I have a spreadsheet with a PRINT button and the following code attached
(thanks to this help site!).  It works great, but I would like to add more
print options from a different worksheet (i.e. “Sales!$A$1:$AD$75”).  I’m not
sure how to write the code since I’m assuming the ActiveSheet… statement
should be replaced with something else??  I tried a couple different ways but
I got errors.

Private Sub cmdPrint_Click()
   
'Bring up an input box to select the page(s) that you want to print

   Dim Ans As Variant
   
'   Ranges for printing:
'
'    Page 1 Load/Generation, Range A1:AF52
'    Page 2 Sales/Purchase, Range A53:AF110
'    Both Pages", Title:="Enter A Number To Print", Default:=3
   
   
   Ans = InputBox(prompt:="1 = Page 1 Load/Generation, Range A1:AF52" & _
           vbLf & "2 = Page 2 Sales/Purchase, Range A53:AF110" & _
           vbLf & "3 = Both Pages", Title:="Enter A Number To Print",
Default:=3)
   
   Select Case Trim(Ans)
       
       Case Is = "1"
           ActiveSheet.PageSetup.PrintArea = "$A$1:$AF$52"
           ActiveSheet.PrintOut Copies:=1
           ActiveSheet.PageSetup.PrintArea = ""
       
       Case Is = "2"
           ActiveSheet.PageSetup.PrintArea = "$A$53:$AF$110"
           ActiveSheet.PrintOut Copies:=1
           ActiveSheet.PageSetup.PrintArea = ""
                     
       Case Is = "3"
           ActiveSheet.PageSetup.PrintArea = "$A$1:$AF$52"
           ActiveSheet.PrintOut Copies:=1
           
           ActiveSheet.PageSetup.PrintArea = "$A$53:$AF$110"
           ActiveSheet.PrintOut Copies:=1
             
           ActiveSheet.PageSetup.PrintArea = ""
           
               Case Else
                   MsgBox "You Must Enter A Number Between 1 & 3"
   End Select

End Sub

Signature

Patti

Paul B - 11 Jan 2006 19:19 GMT
PattiP, here is one way,

Private Sub cmdPrint_Click()

'Bring up an input box to select the page(s) that you want to print

   Dim Ans As Variant

'   Ranges for printing:
'
'  1=  Page 1 Load/Generation, Range A1:AF52
'  2=  Page 2 Sales/Purchase, Range A53:AF110
'  3=  Both Pages", Title:="Enter A Number To Print", Default:=3
'  4= Sheet Sales Range A1:AD75

   Ans = InputBox(prompt:="1 = Page 1 Load/Generation, Range A1:AF52" & _
           vbLf & "2 = Page 2 Sales/Purchase, Range A53:AF110" & _
           vbLf & "3 = Both Pages" & vbLf & _
           "4 = Sheet Sales, Range A1:AD75", Title:="Enter A Number To
Print", Default:=3)

   Select Case Trim(Ans)

       Case Is = "1"
           ActiveSheet.PageSetup.PrintArea = "$A$1:$AF$52"
           ActiveSheet.PrintOut Copies:=1
           ActiveSheet.PageSetup.PrintArea = ""

       Case Is = "2"
           ActiveSheet.PageSetup.PrintArea = "$A$53:$AF$110"
           ActiveSheet.PrintOut Copies:=1
           ActiveSheet.PageSetup.PrintArea = ""

       Case Is = "3"
           ActiveSheet.PageSetup.PrintArea = "$A$1:$AF$52"
           ActiveSheet.PrintOut Copies:=1

           ActiveSheet.PageSetup.PrintArea = "$A$53:$AF$110"
           ActiveSheet.PrintOut Copies:=1
           ActiveSheet.PageSetup.PrintArea = ""

        Case Is = "4"
           Sheets("Sales").PageSetup.PrintArea = "$A$1:$A$10"
           Sheets("Sales").PrintOut Copies:=1
           Sheets("Sales").PageSetup.PrintArea = ""

               Case Else
                   MsgBox "You Must Enter A Number Between 1 & 4"
   End Select

End Sub

>I have a spreadsheet with a PRINT button and the following code attached
> (thanks to this help site!).  It works great, but I would like to add more
[quoted text clipped - 48 lines]
>
> End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.