View Full Version : How to Change casing of the String
Rakesh
07-01-2011, 02:47 AM
Hi Friends,
Hi had a macro to wildcard replacement. The coding is below:
ActiveDocument.Content.Find.Execute _
FindText:="([!^13@]@%^13)", _
MatchWildcards:=True, _
ReplaceWith:="@SI-minor entry hd:\1", _
Replace:=wdReplaceAll
How to change the Casing as Title Case of string "([!^13@]@%^13)".
Thanks,
Rakesh
macropod
07-01-2011, 08:02 PM
Hi Rakesh,
There is no 'Title case' property. When you use the 'Title case' function in Word to convert a string, all that happens is that Word runs a bit of code that captializes the first letter of each Word.
For a wildcard Find/Replace operation that operates on a variable-length string (as yours does), you cannot predicate the Find on the capitalization of the first character of an indeterminate number of words - such predication would only be possible if you knew beforehand how many words were in the string.
Rakesh
07-05-2011, 02:02 AM
Hi Paul,
Is there is any other coding to change the whole Paragraph as Title Case which ends with % at the end of the Paragraph.
Regards,
Rakesh
macropod
07-05-2011, 02:21 AM
Hi Rakesh,
The macro recorder gives:
Selection.Range.Case = wdTitleWord
you should be able to adapt that to a paragraph-based routine. For example:
Sub Demo()
With ActiveDocument.Range
With .Find
.ClearFormatting
.Text = "([!^13@]@%^13)"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found
.InsertBefore "@SI-minor entry hd:"
.Case = wdTitleWord
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
End Sub
Rakesh
07-05-2011, 02:47 AM
Hi Paul,
The Coding has not changing the Casing.
Thanks,
Rakesh
macropod
07-05-2011, 02:53 AM
Works for me ...
Rakesh
07-05-2011, 03:21 AM
Hi Paul,
What's wrong in it. Is not working for me.
Thanks,
Rakesh
macropod
07-05-2011, 03:28 AM
Hi Rakesh,
There is nothing 'wrong' in it. As I said. It works for me - with the Find/Replace expressions you posted (provided there's matching text in the document).
Maybe what is wrong is that you're using the: (a) wrong Find expression; or (b) right Find expression but there is no text matching it.
Rakesh
07-05-2011, 04:27 AM
Hi Paul,
With a slight modification in this part its working now.
I have moved ".Case = wdTitleWord" into front.
Do While .Find.Found
.Case = wdTitleWord
.InsertBefore "@SI-minor entry hd:"
.Collapse wdCollapseEnd
.Find.Execute
Loop
Thanks,
Rakesh
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.