PDA

View Full Version : [SOLVED:] How can I concatenate a hard-coded string and a variable to create a parameter?



ma_roberge
09-21-2016, 01:50 PM
I have written a routine using wildcards that replaces all instances of two spaces or more by one space, but the French version of Word 2007 requires a comma for specifying a minimum number of characters in a find string, e.g., {2,}, whereas Word 2013 requires a semicolon, i.e., {2;}. I have written the following code to set the punctuation required for each of the two versions of Word I could test. It is followed by two calls to the find and replace routine, of which the second is functional but works only in Word 2013. I am thus trying to concatenate the space (between square brackets), the curly brackets, and my variable, but do not know how to achieve what I need. Furthermore, do Word 2010 and 2016 also use the semicolon? Thanks for any help in advance.


Dim strWordVersion As String
Select Case Val(Application.Version)
Case 15 'Version 2013
strWordVersion = ";"
Case 14 'Version 2010
Case 12 'Version 2007
strWordVersion = ","
Case 11 'Version 2003
End Select
Call FindReplaceAll("[ ] & {2 & strWordVersion & }", " ", "Message") 'Incorrect find string
'Call FindReplaceAll("[ ]{2;}", " ", "Message") 'Functional statement

gmaxey
09-21-2016, 05:47 PM
Call FindReplaceAll("[ ]{2" & strWordVersion & "}", " ", "Message")

ma_roberge
09-22-2016, 06:52 AM
From the master himself! Thank you very much, my problem is solved. Each of my subroutine calls is now somewhat longer, but at least my macro works without modification on at least two versions of Word.