Currently I have code (below) that goes through and finds all charts and tables inside my workbook, takes their names as an array and pastes them onto a table as a data validation dropdown so that whomever is using the workbook can decide which tables and graphs to auto generate into a PowerPoint Presentation. Now I am trying to write code that also will do the same for named ranges. So not charts or tables. For some reason this seems to be way harder than I logically thought it would be. If anything I figured getting tables and charts to work would've been more of a headache but that has not been the case
Code and Picture of the aforementioned table are shown below
CODE:
Dim xlBook As Workbook
Dim xlSheet As Worksheet
Dim xlTable As ListObject
Dim xlTableColumn As ListColumn
Dim xlChartObject As ChartObject
Dim xlTableObject As ListObject
Dim ObjectArray() As String
Dim ObjectIndexArray As Integer
Dim ExcRng As Range
'set the book
Set xlBook = ThisWorkbook
'loop through each worksheet
For Each xlSheet In xlBook.Worksheets
'if we have charts
If xlSheet.ChartObjects.Count > 0 Then
'grab each chart name
For Each xlChartObject In xlSheet.ChartObjects
'update count
ObjectArrayIndex = ObjectArrayIndex + 1
ReDim Preserve ObjectArray(ObjectArrayIndex)
'add the chart object to array
ObjectArray(ObjectArrayIndex) = xlChartObject.Name & "-" & xlSheet.Name & "-" & TypeName(xlChartObject)
Next
End If
'if we have tables
If xlSheet.ListObjects.Count > 0 Then
'grab each table name
For Each xlTableObject In xlSheet.ListObjects
'update count
ObjectArrayIndex = ObjectArrayIndex + 1
ReDim Preserve ObjectArray(ObjectArrayIndex)
'add the table object to array
ObjectArray(ObjectArrayIndex) = xlTableObject.Name & "-" & xlSheet.Name & "-" & TypeName(xlTableObject)
Next
End If
Next
'grab sheet
Set xlSheet = xlBook.Worksheets("Export")
'grab table from sheet
Set xlTable = xlSheet.ListObjects("ExportToPowerPoint")
'grab object column from table
Set xlTableColumn = xlTable.ListColumns("Object")
'set the validation dropdown
With xlTableColumn.DataBodyRange.Validation
'delete old
.Delete
'add new data
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(ObjectArray, ",")
'make sure it's a dropdown
.InCellDropdown = True
End With
PICTURE OF TABLE
As you can see from the picture; column A is where I have the references going. And as you can see the one chart and table that I have named so far for my workbook are showing up fine--so my code so far for Graphs and Tables seems to be working great. I now just need it to also populate named ranges on that same column A