Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to print several worksheets does not work!


Can someone see why the below macro does not work?
At first it seems to work, it will print the first worksheet wit
correct range and correct format, but when the next and all othe
worksheets are printed, the format is all wrong (the range is printe
over 4 pages) and it also prints worksheet "Q", although it should b
excluded!

Sub Makro1()
ActiveWorkbook.Unprotect ("password")
ActiveSheet.Unprotect ("password")
Application.ScreenUpdating = False
Sheets("B").Select
Dim NamesToExclude As Variant
Dim wks As Worksheet
Dim AddrToPrint As String
NamesToExclude = Array("A", "Q")
AddrToPrint = "B4:O74"
For Each wks In ThisWorkbook.Worksheets
If wks.Visible = xlSheetVisible Then
If IsNumeric(Application.Match(wks.Name, NamesToExclude, 0)) Then
'skip it
Else
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.78740157480315)
.RightMargin = Application.InchesToPoints(0.393700787401575)
.TopMargin = Application.InchesToPoints(0.590551181102362)
.BottomMargin = Application.InchesToPoints(0.590551181102362)
.HeaderMargin = Application.InchesToPoints(0.393700787401575)
.FooterMargin = Application.InchesToPoints(0.393700787401575)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
wks.Range(AddrToPrint).PrintOut preview:=False
End If
End If
Next wks
Sheets("A").Select
Range("A1").Select
Application.ScreenUpdating = True
ActiveSheet.Protect ("password")
ActiveWorkbook.Protect ("password")
End Sub

I would be very greatful for some hints about what the problem coul
be

--
ulfa
-----------------------------------------------------------------------
ulfah's Profile: http://www.excelforum.com/member.php...fo&userid=2920
View this thread: http://www.excelforum.com/showthread.php?threadid=50722

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro to print several worksheets does not work!

My bet is this line:
With ActiveSheet.PageSetup

You're always working with the activesheet.

How about:
With wks.PageSetup

(I stopped looking after that.)

ulfah wrote:

Can someone see why the below macro does not work?
At first it seems to work, it will print the first worksheet with
correct range and correct format, but when the next and all other
worksheets are printed, the format is all wrong (the range is printed
over 4 pages) and it also prints worksheet "Q", although it should be
excluded!

Sub Makro1()
ActiveWorkbook.Unprotect ("password")
ActiveSheet.Unprotect ("password")
Application.ScreenUpdating = False
Sheets("B").Select
Dim NamesToExclude As Variant
Dim wks As Worksheet
Dim AddrToPrint As String
NamesToExclude = Array("A", "Q")
AddrToPrint = "B4:O74"
For Each wks In ThisWorkbook.Worksheets
If wks.Visible = xlSheetVisible Then
If IsNumeric(Application.Match(wks.Name, NamesToExclude, 0)) Then
'skip it
Else
With ActiveSheet.PageSetup
LeftHeader = ""
CenterHeader = ""
RightHeader = ""
LeftFooter = ""
CenterFooter = ""
RightFooter = ""
LeftMargin = Application.InchesToPoints(0.78740157480315)
RightMargin = Application.InchesToPoints(0.393700787401575)
TopMargin = Application.InchesToPoints(0.590551181102362)
BottomMargin = Application.InchesToPoints(0.590551181102362)
HeaderMargin = Application.InchesToPoints(0.393700787401575)
FooterMargin = Application.InchesToPoints(0.393700787401575)
PrintHeadings = False
PrintGridlines = False
PrintComments = xlPrintNoComments
CenterHorizontally = True
CenterVertically = True
Orientation = xlPortrait
Draft = False
PaperSize = xlPaperA4
FirstPageNumber = xlAutomatic
Order = xlDownThenOver
BlackAndWhite = False
Zoom = False
FitToPagesWide = 1
FitToPagesTall = 1
End With
wks.Range(AddrToPrint).PrintOut preview:=False
End If
End If
Next wks
Sheets("A").Select
Range("A1").Select
Application.ScreenUpdating = True
ActiveSheet.Protect ("password")
ActiveWorkbook.Protect ("password")
End Sub

I would be very greatful for some hints about what the problem could
be.

--
ulfah
------------------------------------------------------------------------
ulfah's Profile: http://www.excelforum.com/member.php...o&userid=29204
View this thread: http://www.excelforum.com/showthread...hreadid=507228


--

Dave Peterson
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
I trying to develop a macro to print my worksheets infomercialscams[_2_] Excel Discussion (Misc queries) 1 May 11th 09 01:15 PM
Print macro won't work Anthony[_5_] Excel Discussion (Misc queries) 3 March 7th 09 08:30 PM
Macro to work only on selected worksheets [email protected] Excel Discussion (Misc queries) 3 January 22nd 07 07:14 PM
How do I print multiple worksheets of a work book onto one page? Kab10 Excel Discussion (Misc queries) 2 May 23rd 06 09:56 AM
Macro to Print several worksheets ulfah Excel Programming 2 December 2nd 05 12:03 AM


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

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"