PDA

View Full Version : [SOLVED:] Calling a Dictionary and its Variables from Another Module



hunter21188
12-06-2015, 05:18 AM
I have a dictionary stored in one module (Module6):


Sub WebcamDict()


Dim dict As Object, Key, val
Set dict = CreateObject("Scripting.Dictionary")


Key = "14 Mile Hill North": val = Array("URL", "Title")
dict.Add Key, val
Key = "14 Mile Hill South": val = Array("URL", "Title")
dict.Add Key, val
Key = "Ash Fork East": val = Array("URL", "Title")
dict.Add Key, val
...

End Sub


In a different module I am trying to call the dictionary and its variables like this:


Sub Images()
Call Module6.WebcamDict

ComboBoxList = Array(CStr(ComboBox4), CStr(ComboBox5), CStr(ComboBox6), CStr(ComboBox7))


i = 1


For Each Ky In ComboBoxList
ActiveWindow.Selection.SlideRange.Shapes("Webcam" & CStr(i)).Fill.UserPicture (dict.Item(Ky)(0))
ActiveWindow.Selection.SlideRange.Shapes("Webcam" & CStr(i)).TextFrame.DeleteText
ActiveWindow.Selection.SlideRange.Shapes("Webcam" & CStr(i)).Line.Visible = msoFalse
ActiveWindow.Selection.SlideRange.Shapes("Webcam" & CStr(i) & "_Text").TextFrame.TextRange.Text = dict.Item(Ky)(1)


i = i + 1


Next


Set dict = Nothing


End Sub


The variable "i" and "Ky" both seem to work fine as tested by
Debug.Print statements. However, I get the error (Object Required) for this line:


ActiveWindow.Selection.SlideRange.Shapes("Webcam" & CStr(i)).Fill.UserPicture (dict.Item(Ky)(0))

If I just include the dictionary in the same module it works perfectly, but I will need to call this from multiple different modules, so I will need to be able to call it along with its variables somehow. Any ideas? Thanks!

hunter21188
12-06-2015, 07:36 AM
To answer my own question, in case anyone else comes across this, the "Dim dict As Object, Key, val" is a local object, so it needs to be made global. In order to do this, the code in the module needed to be changed to this:


Public dict As Object, Key, val
Sub WebcamDict()


Set dict = CreateObject("Scripting.Dictionary")
...