Results 1 to 3 of 3

Thread: Its gone Wild

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    3

    Its gone Wild

    Hi people,

    I have a small syntactical issue

    I have outdated components list with me in a word document and i am using a small Wild card Replacement for that

    Example When i do it manually ...i press find and replace and type this

    ---Text in document----

    [Unit Name]=Carbide Grade A: K1[Internal]
    [Unit Name]=Carbide Grade B: K3[Internal] and so on

    i need to find the string [Unit Name]=Carbide Grade A: K1[Internal]
    and replace it with [CAK1] and similarly i need to find
    [Unit Name]=Carbide Grade B: K3[External] and replace it with CBK3

    Manually i do it but typing this in the Find box
    Unit Name=*Carbide*K1[Internal] and replace it with CAK1

    But since my list is huge and there are lots of documents i am trying to make it automatic here's my code

    VB Code:
    1. Function replwc(source As String, str_search As String, dest As String)
    2.     Selection.Find.ClearFormatting
    3.     Selection.Find.Replacement.ClearFormatting
    4.     With Selection.Find
    5.         .MatchWildcards = True
    6.         .Text = \[\Unit Name=* & source & * & str_search & \[\Internal\]
    7.         .Replacement.Text = dest
    8.         .Forward = True
    9.         .Wrap = wdFindContinue
    10.         .Format = False
    11.         .MatchCase = False
    12.         .MatchWholeWord = False
    13.         .MatchWildcards = True
    14.         .MatchSoundsLike = False
    15.         .MatchAllWordForms = False
    16.     End With
    17.     Selection.Find.Execute Replace:=wdReplaceAll
    18. End Function
    19.  
    20.  
    21. Sub FrepWC()
    22. s = replwc("Carbide Grade A", "K1", "CAK1")
    23. s = replwc("Carbide Grade A", "K3", "CAK3")
    24. s = replwc("Carbide Grade B", "Q1", "CBQ1")
    25. s = replwc("Carbide Grade C", "R1", "CBR1")
    26. End Sub
    I am getting a error on line
    VB Code:
    1. .Text = \[\Carbide Grade A* & source & * & str_search & \[\Internal\]

    How can i get this to work??

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Its gone Wild

    Welcome to the forums.

    What error are you getting?

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Its gone Wild

    This is guess :
    Code:
      .Text = "[Carbide Grade A*" & source & "*" & str_search & "[Internal]"
    If you are in VBA you need speechmarks around text parts.
    Try the above and see if it works.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width