title: Return Dictionary from Function or Sub in VBA
body: <p>I would like to create and initialize a Dictionary object in one sub/function and use it in another.  I could do everything in the same sub but would like to have the code modularized.  This returns "argument not optional" which is the latest error in the latest version of this code that I have tried.  What am I doing wrong?  </p>
  
  <pre><code>Function CreateDictionary() As Dictionary
  
  
  Set aDictionary = New Dictionary
  
  With aDictionary
  
      .Add Key:="key1", Item:="value1"
      .Add Key:="key2", Item:="value2"
  
  
  End With
  
  
  CreateDictionary = aDictionary
  End Function
  
  Sub useDictionary()
  
  myDictionary = CreateDictionary
  
  For Each k In myDictionary.Keys
      MsgBox myDictionary.k
  Next
  
  
  
  End Sub
  </code></pre>