|
-
Feb 27th, 2006, 12:55 AM
#1
Thread Starter
New Member
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:
Function replwc(source As String, str_search As String, dest As String)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.MatchWildcards = True
.Text = \[\Unit Name=* & source & * & str_search & \[\Internal\]
.Replacement.Text = dest
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Function
Sub FrepWC()
s = replwc("Carbide Grade A", "K1", "CAK1")
s = replwc("Carbide Grade A", "K3", "CAK3")
s = replwc("Carbide Grade B", "Q1", "CBQ1")
s = replwc("Carbide Grade C", "R1", "CBR1")
End Sub
I am getting a error on line
VB Code:
.Text = \[\Carbide Grade A* & source & * & str_search & \[\Internal\]
How can i get this to work??
-
Feb 27th, 2006, 07:57 AM
#2
Re: Its gone Wild
Welcome to the forums. 
What error are you getting?
-
Feb 27th, 2006, 08:45 AM
#3
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|