Jalz Posted May 23, 2016 Posted May 23, 2016 Hey Guys I've wrote this function but just can't get it to work. The plan is to inject some content (template) and for it to iterate through each word looking for a formula, i.e. {{If([[CarMake]] = "Volvo"; "Volvo" ; "Other" )}} and evaluate it. I think the calculation I have is working fine, but I can't quite manage to work out how to loop through each word in the content. I've tried to reverse engineer Ray Cologens Mail Merge formula as that custom function kind of did what I needed, but I didn't need all of it. Thanks in advance. MergeText(Template) Let([ start_pos = Position(Template; "{{"; 1; 1); end_pos = Position(Template; "}}"; start_pos; 1); formula = Middle(Template; start_pos + 2; end_pos - start_pos - 2); formula_VARS = Substitute(formula ; ["[[CarMake]]";"$CarMake"]; ["[[CarModel]]";"$CarModel"]; ["[[CarType]]";"$CarType"] ); original_formula = "{{" & formula & "}}"; evaluated_formula = If(EvaluationError(Evaluate(formula_VARS)); "Invalid Formula"; Evaluate(formula_VARS)) ] ; Case( Right(Template ; 1 ) <> ¶ ; MergeText(Template & ¶) ; start_pos > 0 and end_pos > start_pos ; MergeText(Substitute (Template ; original_formula ; evaluated_formula ) ) ; Template ) )
comment Posted May 23, 2016 Posted May 23, 2016 You did not explain what the function is supposed to do. Looking at it superficially, it would seem a simple Substitute() could do the job?
Recommended Posts
This topic is 3104 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now