#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Print Macro

I currently have the below Macro that will change the paper size and
position. How do I add a line that will make the contents in the spreadsheet
to fit on one page. However, I have about 152 pages. Help - thanks! I get
errors when adding ActiveSheet.PageSetup.PrintArea = "". Do I need to place
it in a certain order. See below for entire Macro.

mySht.PageSetup.PaperSize = xlPaperLegal
mySht.PageSetup.Orientation = xlLandscape


My current Macro: ***


Sub ExportDatabaseToSeparateFiles()
'Export is based on the value in the desired column
Dim myCell As Range
Dim mySht As Worksheet
Dim myName As String
Dim myArea As Range
Dim myShtName As String
Dim KeyCol As String
Dim myField As Integer

myShtName = ActiveSheet.Name
KeyCol = InputBox("What column letter to use as key?")

Set myArea = Intersect(ActiveCell.CurrentRegion, Range(KeyCol &
"1").EntireColumn).Cells

Set myArea = myArea.Offset(1, 0).Resize(myArea.Rows.Count - 1, 1)
myField = myArea.Column - ActiveCell.CurrentRegion.Cells(1).Column + 1

For Each myCell In myArea
On Error GoTo NoSheet
myName = Worksheets(myCell.Value).Name
GoTo SheetExists:
NoSheet:
Set mySht = Worksheets.Add(Befo=Worksheets(1))
mySht.Name = myCell.Value
With myCell.CurrentRegion
..AutoFilter Field:=myField, Criteria1:=myCell.Value
..SpecialCells(xlCellTypeVisible).Copy _
mySht.Range("A1")
mySht.Cells.EntireColumn.AutoFit
mySht.PageSetup.PaperSize = xlPaperLegal
mySht.PageSetup.Orientation = xlLandscape

..AutoFilter
End With
Resume
SheetExists:
Next myCell

For Each mySht In ActiveWorkbook.Worksheets
If mySht.Name = myShtName Then
Exit Sub
Else
mySht.Move
ActiveWorkbook.SaveAs "Workbook " & ActiveSheet.Name & ".xls"
ActiveWorkbook.Close
End If
Next mySht
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Print Macro

I'm not sure if you're really using activesheet, but maybe...

With mySht.PageSetup
.PrintArea = ""
.PaperSize = xlPaperLegal
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = 1
End With

Are you sure that the activeprinter really does legal size paper???

Nikki wrote:

I currently have the below Macro that will change the paper size and
position. How do I add a line that will make the contents in the spreadsheet
to fit on one page. However, I have about 152 pages. Help - thanks! I get
errors when adding ActiveSheet.PageSetup.PrintArea = "". Do I need to place
it in a certain order. See below for entire Macro.

mySht.PageSetup.PaperSize = xlPaperLegal
mySht.PageSetup.Orientation = xlLandscape

My current Macro: ***

Sub ExportDatabaseToSeparateFiles()
'Export is based on the value in the desired column
Dim myCell As Range
Dim mySht As Worksheet
Dim myName As String
Dim myArea As Range
Dim myShtName As String
Dim KeyCol As String
Dim myField As Integer

myShtName = ActiveSheet.Name
KeyCol = InputBox("What column letter to use as key?")

Set myArea = Intersect(ActiveCell.CurrentRegion, Range(KeyCol &
"1").EntireColumn).Cells

Set myArea = myArea.Offset(1, 0).Resize(myArea.Rows.Count - 1, 1)
myField = myArea.Column - ActiveCell.CurrentRegion.Cells(1).Column + 1

For Each myCell In myArea
On Error GoTo NoSheet
myName = Worksheets(myCell.Value).Name
GoTo SheetExists:
NoSheet:
Set mySht = Worksheets.Add(Befo=Worksheets(1))
mySht.Name = myCell.Value
With myCell.CurrentRegion
.AutoFilter Field:=myField, Criteria1:=myCell.Value
.SpecialCells(xlCellTypeVisible).Copy _
mySht.Range("A1")
mySht.Cells.EntireColumn.AutoFit
mySht.PageSetup.PaperSize = xlPaperLegal
mySht.PageSetup.Orientation = xlLandscape

.AutoFilter
End With
Resume
SheetExists:
Next myCell

For Each mySht In ActiveWorkbook.Worksheets
If mySht.Name = myShtName Then
Exit Sub
Else
mySht.Move
ActiveWorkbook.SaveAs "Workbook " & ActiveSheet.Name & ".xls"
ActiveWorkbook.Close
End If
Next mySht
End Sub


--

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
Macro to hide rows with a certain cell empty then set print area and print tahrah Excel Programming 12 January 9th 07 03:47 AM
Pivot Table macro to set print area and print details of drill down data Steve Haskins Excel Discussion (Misc queries) 2 December 28th 05 04:59 PM
Macro to open print window and set to print entire workbook retseort Excel Discussion (Misc queries) 1 October 27th 05 11:00 PM
Create a print macro that would automatically select print area? wastedwings Excel Worksheet Functions 7 August 22nd 05 10:36 PM
Need Help w/ Print Macro to Print All Visible Sheets (including Charts) in a Workbook will Excel Programming 3 September 23rd 04 08:05 PM


All times are GMT +1. The time now is 11:56 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"