Access return object value from invoke vba

Hi All,

Can anyone please guide me through how I can access object value that has dictionary in it

  1. I have used invoke VBA where I have written function code and returning dictionary as output value, but we know it return in object type. It’s doing so, but how can I access those dictionaries value from it.

This is what I’m getting in object, that has two dictionary key C, D.


-Ensure you have a reference to the Microsoft Scripting Runtime**:

*In the VBA editor, go to Tools > References.
*Find and check Microsoft Scripting Runtime.

Sub AccessDictionary()
    Dim dict As Object
    Set dict = GetDictionary()
    Dim key As Variant
    For Each key In dict.Keys
        Debug.Print "Key: " & key & ", Value: " & dict(key)
    Next key
End Sub


Your output datatype should be Dictionary(of X, Y) (x and y to match your output). Then you just reference it like you would any dictionary… myDict(“key”) will give you the value for that key.

@bavyaravu133 thanks for reply, but I have no issue for creating dictionary in vba. It’s done.
Here is the written code.

Function GetModifiedDictionary(strName As String) As Object
    Dim modifiedDict As Object
    Dim key As String

    Set modifiedDict = CreateObject("Scripting.Dictionary")
    ' Copy the input dictionary to the modified dictionary
    ' Modify the dictionary
    modifiedDict.Add "C", 3
    modifiedDict.Add "D", strName
    ' Return the modified dictionary
    Set GetModifiedDictionary = modifiedDict
End Function

So this function returning the dictionary in output for invoke vba return value will be of object type.

@postwick thanks for reply, but it is of object type return value of invoke vba

So fix your code so it returns a dictionary.

Hi @postwick sorry for misunderstanding Invoke VBA activity only object value

Set it as a dictionary not an object.