R
Robert
I am creating multiple worksheets in a single workbook.
The workbook is being created by another application (Data
Junction). Each worksheet has the same columns, however
the number of worksheets (and their corrsponding sheet
names) will vary on a monthly basis.
I have been able to succssfully format a single worksheet,
but am having trouble applying the same
formatting/functions to multiple sheets in the same
workbook.
Example code is provided below...How might I apply the For
Each...Next syntax around this so that all worksheets are
formatted the same?
Thanks
*******
'Define the Excel Application Object
Dim xlApp As Object
'Create the Excel Object
Set xlApp = CreateObject("Excel.Application")
'Open the desired Excel File
xlApp.Application.Workbooks.Open "c:sample.xls"
'Insert Rowsfor Control Totals
xlApp.Application.Rows("1:3").Select
xlApp.Application.Selection.Insert Shift = "xlDown"
'Calculate Totals
xlApp.Application.Range("K2").Select
xlApp.Application.ActiveCell.FormulaR1C1 = "=SUM(R[3]C:R
[65534]C)"
'Format Totals
xlApp.Application.Range("K2:AD2").Select
xlApp.Application.Selection.Style = "Comma"
'Freeze Pane
xlApp.Application.Range("D5").Select
xlApp.Application.ActiveWindow.FreezePanes = TRUE
'Format field to 3 decimal places
xlApp.Application.Columns("H:H").Select
xlApp.Application.Selection.NumberFormat
'Autofit Columns
xlApp.Application.Cells.Select
xlApp.Application.Cells.EntireColumn.AutoFit
The workbook is being created by another application (Data
Junction). Each worksheet has the same columns, however
the number of worksheets (and their corrsponding sheet
names) will vary on a monthly basis.
I have been able to succssfully format a single worksheet,
but am having trouble applying the same
formatting/functions to multiple sheets in the same
workbook.
Example code is provided below...How might I apply the For
Each...Next syntax around this so that all worksheets are
formatted the same?
Thanks
*******
'Define the Excel Application Object
Dim xlApp As Object
'Create the Excel Object
Set xlApp = CreateObject("Excel.Application")
'Open the desired Excel File
xlApp.Application.Workbooks.Open "c:sample.xls"
'Insert Rowsfor Control Totals
xlApp.Application.Rows("1:3").Select
xlApp.Application.Selection.Insert Shift = "xlDown"
'Calculate Totals
xlApp.Application.Range("K2").Select
xlApp.Application.ActiveCell.FormulaR1C1 = "=SUM(R[3]C:R
[65534]C)"
'Format Totals
xlApp.Application.Range("K2:AD2").Select
xlApp.Application.Selection.Style = "Comma"
'Freeze Pane
xlApp.Application.Range("D5").Select
xlApp.Application.ActiveWindow.FreezePanes = TRUE
'Format field to 3 decimal places
xlApp.Application.Columns("H:H").Select
xlApp.Application.Selection.NumberFormat
'Autofit Columns
xlApp.Application.Cells.Select
xlApp.Application.Cells.EntireColumn.AutoFit