The snippet I included below puts the data from an Excel table into a dictionary, where the first column of the table is the file name (key) and the second column is the path to the file. The code works completely fine, however there would be several other tables that I would like to do this with, creating a bunch of dictionaries with different filenames and locations, for different purposes.
Currently I create these dictionaries separately, all of them in their own little sub. This of course means I have multiple versions of pretty much the same code: quite cumbersome.
My problem is I have no idea how I could create a dynamic number of variables to accomodate my tables. Pretty sure thats not even possible. I would appreciate some suggestions on what I could look into, what general direction is worth exploring.
Sub locationsObject()
Dim locationTable As ListObject
Dim lrow As Range
Set locationTable = ActiveSheet.ListObjects("locationTable")
Set Locations = CreateObject("Scripting.Dictionary")
'Create dictionary with locations and their names from the location table. Check if locations are valid
For Each lrow In locationTable.ListColumns(1).DataBodyRange.rows
Locations(lrow.Value) = lrow.Offset(0, 1).Value
'Debug.Print Locations(lrow.Value)
'Debug.Print lrow.Value
checkIfExists Locations(lrow.Value), "The path of " & lrow.Value & " does not exist: " & Locations(lrow.Value) & vbCrLf & "Please provide a valid path."
Next lrow
End Sub