I have the following two subroutines:
Rem Attribute VBA_ModuleType=VBAModule
Sub FixPlatformsSelection()
Dim fndList As Object
Set fndList = CreateObject("Scripting.Dictionary")
fndList.Add "3DO Interactive Multiplayer", "3DO"
fndList.Add "Nintendo 3DS", "3DS"
fndList.Add "Ajax", "AJAX"
fndList.Add "Xerox Alto", "ALTO"
fndList.Add "Amiga CD32", "AMI32"
fndList.Add "Amiga", "AMI"
fndList.Add "Apple I", "APPI"
fndList.Add "Apple IIe", "APPIIE"
fndList.Add "Apple IIGS", "APPGS"
fndList.Add "Apple II Plus", "APPII+"
fndList.Add "Apple II series", "APPII"
fndList.Add "Apple II", "APPII"
For Each strKey In fndList.Keys()
Selection.Replace What:=strKey, Replacement:=fndList(strKey), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next strKey
End Sub
Rem Attribute VBA_ModuleType=VBAModule
Sub FixPlatformsWorkbook()
Dim fndList As Object
Set fndList = CreateObject("Scripting.Dictionary")
fndList.Add "3DO Interactive Multiplayer", "3DO"
fndList.Add "Nintendo 3DS", "3DS"
fndList.Add "Ajax", "AJAX"
fndList.Add "Xerox Alto", "ALTO"
fndList.Add "Amiga CD32", "AMI32"
fndList.Add "Amiga", "AMI"
fndList.Add "Apple I", "APPI"
fndList.Add "Apple IIe", "APPIIE"
fndList.Add "Apple IIGS", "APPGS"
fndList.Add "Apple II Plus", "APPII+"
fndList.Add "Apple II series", "APPII"
fndList.Add "Apple II", "APPII"
For Each sht In ActiveWorkbook.Worksheets
For Each strKey In fndList.Keys()
sht.Cells.Replace What:=strKey, Replacement:=fndList(strKey), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next strKey
Next sht
End Sub
How do I remove the fndList
dictionary from the subroutines and move it to somewhere else so that all subroutines can access it as well? I have two routines that need this dictionary, and don't want to have to maintain two copies of the same code. Is there a special place to put "global" variables in VBA? Thanks.
[edit]
I tried placing the declarations outside the procedure:
Public fndList As Object
Set fndList = CreateObject("Scripting.Dictionary")
fndList.Add "3DO Interactive Multiplayer", "3DO"
fndList.Add "Nintendo 3DS", "3DS"
fndList.Add "Ajax", "AJAX"
fndList.Add "Xerox Alto", "ALTO"
fndList.Add "Amiga CD32", "AMI32"
fndList.Add "Amiga", "AMI"
fndList.Add "Apple I", "APPI"
fndList.Add "Apple IIe", "APPIIE"
fndList.Add "Apple IIGS", "APPGS"
fndList.Add "Apple II Plus", "APPII+"
fndList.Add "Apple II series", "APPII"
fndList.Add "Apple II", "APPII"
Rem Attribute VBA_ModuleType=VBAModule
Sub FixPlatformsSelection()
For Each strKey In fndList.Keys()
Selection.Replace What:=strKey, Replacement:=fndList(strKey), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next strKey
End Sub
But I get a compile error: Invalid outside procedure.