Hello - I have made something that opens an excel document that was just exported. The workbook has 10 tabs. I wish there was someway to edit all the tabs instead of doing it tab by tab in the code. Is there a way to do that? Right now I am only able to do "Sheet1" of course.
Code:
Private Sub OpenAndFormatExcel()
Dim filePath As String
filePath = "C:\Users\Andy\Documents\Andy\Test.xlsx"
Dim XL As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set XL = New Excel.Application
Set xlBook = XL.Workbooks.Open(filePath)
Set xlSheet = xlBook.Worksheets("Sheet1")
XL.Visible = True
FreezeRow
With xlSheet
With .Range("A1:L1")
.HorizontalAlignment = Excel.xlCenter
.Font.Bold = True
.Columns.AutoFit
.EntireColumn.AutoFit
End With
End With
XL.DisplayAlerts = False
xlBook.Save
'*** uncomment to keep open
'xlBook.Close True
XL.DisplayAlerts = True
Set xlSheet = Nothing
Set xlBook = Nothing
Set XL = Nothing
End Sub
Sub FreezeRow()
Rows("2:2").Select
ActiveWindow.FreezePanes = True
End Sub
Comment