I do this in several apps. I use an array of data pairs - the macro (variable) name and the value. The function below evaluates a string, replacing every macro found with it's corresponding value.
 Code:
; ======================================================================
; Search a string for macros & replace with assigned data
Function ProcessMacros($_String)

  Dim $_Macro						; macro enumerator
  Dim $_Replace						; replacement value
  Dim $_I						; index pointer

  ; Environment Variable Processing
  $_String = ExpandEnvironmentVars($_String)		; expand vars first

  For $_I = 0 to UBound($aMACROS, 2)
    $_Macro = $aMACROS[0, $_I]				; macro name
    $_Replace = $aMACROS[1, $_I]			; replacement value

    ; replace the macro with the value
    If $_Replace
      $_String = Join(Split($_String, $_Macro), $_Replace)
    EndIf
  Next

  $ProcessMacros = $_String
  Exit 0

EndFunction
$aMACROS is a two-dimensional array of "MacroName","Replacement Value". I load the array from a CSV file. My macros look like "#MACRO#", but this should not matter as they are all in the file. Should be easy to test with your "$MACRO" format.

Note that any macro in the file that does not have a replacement macro identified will not be changed.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D