Sub Test()
Dim objDict As Object
Dim strText As String
' Create dictionary
Set objDict = CreateObject("Scripting.Dictionary")
' Add first set of data to dictionary manualy
objDict.Add "k1", "v1"
objDict.Add "k2", "v2"
objDict.Add "k3", "v3"
' "Serialize" dictionary to delimited text string, and display it
strText = Dict2String(objDict)
MsgBox strText
' Build a new set of data as delimited key/value pairs
strText = "key1" & vbTab & "value1" & vbCrLf
strText = strText & "key2" & vbTab & "value2" & vbCrLf
strText = strText & "key3" & vbTab & "value3" & vbCrLf
strText = strText & "key4" & vbTab & "value4" & vbCrLf
strText = strText & "key5" & vbTab & "value5" & vbCrLf
' Replace contents of dictionary you data in delimited text string
String2Dict objDict, strText
' Extract new values from dictionary to text string, and display it
strText = Dict2String(objDict)
MsgBox strText
End Sub
Function Dict2String(objDict As Object) As String
Dim strKey As Variant
Dim strExport As String
' For each dictionary item, add to text string using delimiters
For Each strKey In objDict.Keys()
strExport = strExport & strKey & vbTab & objDict(strKey) & vbCrLf
Next
' Return serialized string
Dict2String = strExport
End Function
Sub String2Dict(objDict As Object, strText As String)
Dim arrPair() As String
Dim arrField() As String
' Empty dictionary
objDict.RemoveAll
' First split text string into each data item
arrPair = Split(strText, vbCrLf)
' Process each items data
For Each strPair In arrPair
If strPair <> "" Then
' Second split key and value values apart
arrField = Split(strPair, vbTab)
' Add this paot to dictionary
objDict.Add arrField(0), arrField(1)
End If
Next
End Sub
~bp
This feels doable, but need a bit more context and info.
~bp