I have a subroutine with optional parameters
Public Sub FaR_Wild_Stories_Extras(ByVal rngStory As Word.Range, _
ByVal strSearch As String, ByVal strReplace As String, _
Optional extra1 As String = "", Optional extra2 As String = "")
With rngStory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = strSearch
.Replacement.Text = strReplace
.Forward = True
.MatchWildcards = True
.MatchCase = True
.IgnorePunct = True
.IgnoreSpace = True
.Format = False
.Wrap = wdFindContinue
If extra1 <> "" Then eval(extra1)
If extra2 <> "" Then eval(extra2)
.Execute Replace:=wdReplaceAll
End With
End Sub
I want to be able to place something like ".font.size=14" or .MatchDiacritics = False for example in extra1 and evaluate it, so that, when invoking a find and replace subroutine if there are specific extra params I want to include in the find and replace as a one time thing, I don't have to create a whole separate sub for it.
Is there a way to do this? Eval() doesn't seem to exist in word VBA. Object.string isn't possible, is there some smarter way I could structure my code other than duplicating the subroutine or having a subroutine with 10s of rarely used, optional arguments?
For a more generalised case, is it possible to call a sub like this, or structure code by passing arguments cleverly to have the same effect
...
call Example , true, ".prop1=5", ".prop2=6"
...
Sub Example1(x, Optional param1 As String, Optional param2 As String)
With Application.ExampleObject
.property1 = "foo"
.property2 = x
Expand (param1)
Expand (param2)
.excecute
End With
End Sub
Evaluate(), but I'm completely uncertain whether or not this would workevaluate("sum(a1:d4))")