MEUserII
Board Regular
- Joined
- Oct 27, 2017
- Messages
- 91
- Office Version
- 365
- 2021
- 2019
- 2016
- 2013
- Platform
- Windows
I am trying to write a Macro that would select the Active Table in the Active Sheet in the Active Workbook for data stored in "C3:H9".
I know the following VBA references can be used: "Application.ActiveWorkbook.ActiveSheet.ActiveCell" can be used to refer to the ActiveCell as mentioned in Link 1, and "ActiveSheet.ActiveCell.CurrentRegion.Select" can be used to refer to the rectangular block of cells surrounded by one or more blank rows or columns as mentioned in Link 2, and "ActiveCell.ListObject.Name" can be used to refer to the active table as mentioned in Link 3.
My question then is: why does the below code not work for referring to the Active Table in the Active Sheet in the Active Workbook by using Application.ActiveWorkbook.ActiveSheet.ActiveCell.ListObject.Name?
Link 1: https://www.experts-exchange.com/questions/27513085/Format-Excel-From-MS-Access-VBA.html
Link 2: https://bettersolutions.com/excel/cells-ranges/vba-selecting-cells.htm
Link 3: https://stackoverflow.com/questions/37215665/referencing-active-table-in-vba
Sub Macro1()
Range("C3:H9").Select
Dim Table1 As ListObject
Set Table1 = ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)
Range("C3").Select
Application.ActiveWorkbook.ActiveSheet.ActiveCell.ListObject.Name.TableStyle = "TableStyleLight1"
End Sub
I know the following VBA references can be used: "Application.ActiveWorkbook.ActiveSheet.ActiveCell" can be used to refer to the ActiveCell as mentioned in Link 1, and "ActiveSheet.ActiveCell.CurrentRegion.Select" can be used to refer to the rectangular block of cells surrounded by one or more blank rows or columns as mentioned in Link 2, and "ActiveCell.ListObject.Name" can be used to refer to the active table as mentioned in Link 3.
My question then is: why does the below code not work for referring to the Active Table in the Active Sheet in the Active Workbook by using Application.ActiveWorkbook.ActiveSheet.ActiveCell.ListObject.Name?
Link 1: https://www.experts-exchange.com/questions/27513085/Format-Excel-From-MS-Access-VBA.html
Link 2: https://bettersolutions.com/excel/cells-ranges/vba-selecting-cells.htm
Link 3: https://stackoverflow.com/questions/37215665/referencing-active-table-in-vba
Sub Macro1()
Range("C3:H9").Select
Dim Table1 As ListObject
Set Table1 = ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)
Range("C3").Select
Application.ActiveWorkbook.ActiveSheet.ActiveCell.ListObject.Name.TableStyle = "TableStyleLight1"
End Sub