Expand|Select|Wrap|Line Numbers
- 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