I have a spreadsheet (Format Reports.xls) that when it opens kicks off a macro. The macro then opens a different spreadsheet file, does formatting, closes the file, moves on to open other files to do the same type of formatting.
This is an excerpt of my macro code in "ThisWorkbook" of file "Format Reports.xls" which is the driver file that is opened:
The problem I am having is that the top half of the code in the fmt2 macro is working on the file "detail report 1.xls" including this code:
but the second half from the ActiveSheet.PageSetup command down is being executed on the file "Format Report.xls" rather then the file "detail report 1.xls":
I've looked up some options in this forum but everything I've tried hasn't worked. How do I identify the file "detail report 1.xls" to be the focus of the PageSetup command?
Thanks!
This is an excerpt of my macro code in "ThisWorkbook" of file "Format Reports.xls" which is the driver file that is opened:
Code:
Public Sub Workbook_Open()
Workbooks.Open Filename:= _
"C:\detail report 1.xls"
Application.Run "'Format Reports.xls'!ThisWorkbook.detail_report_1"
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Formatting Complete.xls"
End Sub
Sub detail_report_1()
Application.Run "'Format Reports.xls'!ThisWorkbook.fmt2"
(other misc formatting code)
ActiveWorkbook.SaveAs Filename:= _
"C:\detail report 1.xls" _
, FileFormat:=xlExcel5, Password:="", WriteResPassword:="password", _
ReadOnlyRecommended:=True, CreateBackup:=False
ActiveWindow.Close
End Sub
Sub fmt2()
With Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Selection.Font.Bold = True
Rows("2:2").Select
ActiveWindow.FreezePanes = True
Cells.Select
Cells.EntireColumn.AutoFit
Selection.ColumnWidth = 6.14
Cells.EntireRow.AutoFit
Cells.EntireColumn.AutoFit
Selection.ColumnWidth = 8.14
Cells.EntireRow.AutoFit
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
Cells.EntireRow.AutoFit
Range("A1").Select
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$1"
.PrintTitleColumns = ""
.LeftHeader = ""
.CenterHeader = "&A"
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = "Page &P of &N"
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.675)
.BottomMargin = Application.InchesToPoints(0.675)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
End With
End Sub
The problem I am having is that the top half of the code in the fmt2 macro is working on the file "detail report 1.xls" including this code:
Code:
Rows("2:2").Select
ActiveWindow.FreezePanes = True
but the second half from the ActiveSheet.PageSetup command down is being executed on the file "Format Report.xls" rather then the file "detail report 1.xls":
Code:
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$1"
.PrintTitleColumns = ""
.LeftHeader = ""
.CenterHeader = "&A"
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = "Page &P of &N"
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.675)
.BottomMargin = Application.InchesToPoints(0.675)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
End With
I've looked up some options in this forum but everything I've tried hasn't worked. How do I identify the file "detail report 1.xls" to be the focus of the PageSetup command?
Thanks!