Consulting

Results 1 to 3 of 3

Thread: How can I concatenate a hard-coded string and a variable to create a parameter?

  1. #1

    How can I concatenate a hard-coded string and a variable to create a parameter?

    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

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Call FindReplaceAll("[ ]{2" & strWordVersion & "}", " ", "Message")
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •