Using a macro to open another workbook and change page orientation.
Posted by MDL on May 23, 2001 3:19 PM
I have used the "record Macro" option to save a macro that opens another workbook and changes it's file orientation before printing. (The code is below.) The problem is that it changes the orientation on the workbook the macro is saved in, not in the workbook I just opened. Any idea what I'm doing wrong? TIA!
Workbooks.Open FileName:="\\FIL-MOR1\SYS\revenue\monthend\monthresult.csv"
With ActiveSheet.PageSetup
.PrintTitleRows = "$5:$7"
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.CenterFooter = "Page &P of &N"
.Orientation = xlLandscape
End With
Range("C:D,K:K").Select
Range("K1").Activate
Selection.NumberFormat = "0.0%"
Range("E:F,H:I").Select
Range("H1").Activate
Selection.NumberFormat = "#,##0"
Range("G:G,J:J").Select
Range("J1").Activate
Selection.NumberFormat = "0.00"
Columns("C:K").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.ShrinkToFit = False
.MergeCells = False
End With
Rows("6:6").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Range("A4:K107").Select
Selection.Columns.AutoFit
Range("B1").Select
ActiveWorkbook.SaveAs FileName:="F:\revenue\monthend\monthresult.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False