MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 30th, 2004, 05:00 PM   #1
Tonyson
 
Join Date: May 2002
Location: Dublin, CA.
Posts: 109
Default print macro

I did a search on this board for a print macro and found one that was submitted by Ian Mac back in 2/21/2002:


Sub PrintPages()
Dim f, t As Integer

f = InputBox("Select start page 1 to 10", "Print From")
t = InputBox("Select end page " & f & " to 10", "Print To")

If MsgBox("Do you wish to print pages " & f & " to " & t, vbYesNo, "Confirm print") = vbYes Then
ThisWorkbook.PrintOut f, t
Else
End If

End Sub

What I would like your help in editing this macro to print a worksheet not workpages with with the same MsgBoxes to print 1 to 11 pages in my worksheet. :o
Tonyson is offline   Reply With Quote
Old Mar 30th, 2004, 05:06 PM   #2
DRJ
MrExcel MVP
 
DRJ's Avatar
 
Join Date: Feb 2002
Location: California
Posts: 3,857
Default

replace

ThisWorkbook.PrintOut f, t

with

Sheets("Sheet1").PrintOut f, t
__________________
Excel VBA Training and Certification (Lesson 1 is free)
<hr>

<hr>-Jacob
DRJ is offline   Reply With Quote
Old Mar 30th, 2004, 05:29 PM   #3
Tonyson
 
Join Date: May 2002
Location: Dublin, CA.
Posts: 109
Default Re: print macro

I get a Run-time error '9':
Subscript out of range
Tonyson is offline   Reply With Quote
Old Mar 30th, 2004, 05:32 PM   #4
TommyGun
MrExcel MVP
 
TommyGun's Avatar
 
Join Date: Dec 2002
Location: Clear Lake, TX
Posts: 4,202
Default Re: print macro

Change the Sheet name to a valid sheet...or just use...
Code:
ActiveSheet.PrintOut f, t
TommyGun is offline   Reply With Quote
Old Mar 30th, 2004, 06:00 PM   #5
Tonyson
 
Join Date: May 2002
Location: Dublin, CA.
Posts: 109
Default Re: print macro


That worked great
Thank you TommyGun and you too DRJ.
Tonyson is offline   Reply With Quote
Old Mar 30th, 2004, 06:40 PM   #6
Tonyson
 
Join Date: May 2002
Location: Dublin, CA.
Posts: 109
Default Re: print macro

One more question: I want to add this:

copies = Application.InputBox("How many copies ?", Type:=1)

Where do I insert this if it works.
Tonyson is offline   Reply With Quote
Old Mar 30th, 2004, 08:08 PM   #7
Tonyson
 
Join Date: May 2002
Location: Dublin, CA.
Posts: 109
Default Re: print macro

Where and how can I enter the number of copies I want in this macro.
Tonyson is offline   Reply With Quote
Old Mar 30th, 2004, 08:20 PM   #8
TommyGun
MrExcel MVP
 
TommyGun's Avatar
 
Join Date: Dec 2002
Location: Clear Lake, TX
Posts: 4,202
Default Re: print macro

Code:
ActiveSheet.PrintOut From:=f, To:=t, Copies:=copies
TommyGun is offline   Reply With Quote
Old Mar 30th, 2004, 08:41 PM   #9
Tonyson
 
Join Date: May 2002
Location: Dublin, CA.
Posts: 109
Default Re: print macro

Thanks!
I chanted
ActiveSheet.PrintOut From:=f, To:=t, Copies:=copies
to
ActiveSheet.PrintOut From:=f, To:=t, Copies:=3
and it prints 4 copies instead of 3. Any reason why?
:o
Tonyson is offline   Reply With Quote
Old Mar 30th, 2004, 08:46 PM   #10
TommyGun
MrExcel MVP
 
TommyGun's Avatar
 
Join Date: Dec 2002
Location: Clear Lake, TX
Posts: 4,202
Default Re: print macro

According to Microsoft Help, the copies property sets the number of copies to print...
Quote:
Originally Posted by Microsoft Help
Copies Optional Variant. The number of copies to print. If this argument is omitted, one copy is printed.
Are you sure it is printing an extra copy?
TommyGun is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 05:12 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.