Consulting

Results 1 to 3 of 3

Thread: Duplicating/modifying text to prevent endless retyping Update required

  1. #1

    Duplicating/modifying text to prevent endless retyping Update required

    Thanks to previous help I received here I had a macro that would take a string of letters and numbers with a set format and reproduce that string with the letters A,B,C,D, etc. after words. For example:

    UF12-00123 would become "UF12-00123", "UF12-00123A", "UF12-00123B" etc.

    Unfortunately, our process changed and now are number strings are randomized with numbers and letters with the only repeatable pattern being the total number of symbols i.e. XXXX-XXXXX. This has now broken the macro I was using as the macro specifically looked for the format of "??##-#####" I looked around thinking there was a symbol that encompassed any letter or number but i have failed. Please help!

    Thank you,
    Steve


    This was the macro i was using:

    Sub process()
    Dim myPar As Paragraph
    Dim myStr As String
    Dim myStr2 As String
    For Each myPar In ActiveDocument.Paragraphs
    myPar.Range.Select
    Selection.End = Selection.End - 1
    If Selection Like "??##-#####" Then
    myStr = Selection
    If myStr <> "" Then
    myStr = Chr(34) & myStr & Chr(34) & ", " & Chr(34) & myStr & "A" & Chr(34) & ", " & Chr(34) & myStr & "B" & Chr(34) & ", " & Chr(34) & myStr & "C" & Chr(34) & ", " _
    & Chr(34) & myStr & "D" & Chr(34) & ", " & Chr(34) & myStr & "E" & Chr(34) & ", " & Chr(34) & myStr & "F" & Chr(34) & ", " & Chr(34) & myStr & "G" & Chr(34) & ", " _
    & Chr(34) & myStr & "H" & Chr(34) & ", " & Chr(34) & myStr & "J" & Chr(34)
    If myStr2 = "" Then
    myStr2 = myStr
    Else
    myStr2 = myStr2 & ", " & myStr
    End If
    End If
    End If

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    What is wrong with: If Selection Like "????-?????" Then
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    ????-????? turns out is exactly what I had in my head when this worked. Thank you so much for the painfully obvious solution!

Posting Permissions

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