Hi Raj,
I'm sorry that I didn't completely understand your original post.
You can still manually accomplish what you want using the procedures in my
first reply, but that would be a very tedious process.
With the following macro you can accomplish your task much more easily.
Sub ChangeBoldItalicToTags()
Dim MyRange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "<bold>^&</bold>"
.Forward = True
.Wrap = wdFindStop
.Format = True
.Font.Bold = True
Do While .Execute() = True
Set MyRange = Selection.Range
MyRange.Collapse Direction:=wdCollapseEnd
MyRange.Expand wdCharacter
MyRange.MoveStart wdCharacter, 1
If MyRange.Font.Italic = True Then
MyRange.MoveStart wdCharacter, -1
Selection.Collapse Direction:=wdCollapseStart
.Execute Replace:=wdReplaceOne
Selection.Font.Bold = False
With MyRange.Find
.Text = ""
.Replacement.Text = "<italic>^&</italic>"
.Forward = True
.Wrap = wdFindStop
.Format = True
.Font.Italic = True
.Execute Replace:=wdReplaceOne
End With
MyRange.Font.Italic = False
End If
Selection.Collapse Direction:=wdCollapseEnd
Selection.MoveStart wdCharacter, 1
Loop
.ClearFormatting
.Replacement.Text = ""
End With
Set MyRange = Nothing
End Sub
Note that this macro will find only bold text followed immediately by italic
text with no normal text in between. In particular, if there is a space with
normal formatting between the bold and italic text, the macro will regard the
space as normal text separating the bold text and the italic text.
Also note that the macro includes code for removing the bold and italic
formatting when the tags are added. If you don't want that to happen remove
the following lines from the macro.
Selection.Font.Bold = False
MyRange.Font.Italic = False
--
Hope this helps,
Pesach Shelnitz
My Web site:
http://makeofficework.com
raj said:
Dear Sir,
Thank you for your kind and detailed explanation.
I need to find bold and italic in one go.
I need to find [boldtext] [italictext] and replace with
<bold>boldtext</bold> <italic>italictext</italic>.
[boldtext] [normaltext] [italictext] should remain undisturbed.
i.e. italic text immediatly following bold text or bold text immediatly
following italic text.
Once again thanks for your time and support. Raj
Pesach Shelnitz said:
Hi Raj,
This can be done using the Find and Replace feature as follows.
For bold text:
1. Press Ctrl+H to open the Find and Replace dialog box.
2. Click More.
3. Click Formatting.
4. Click Font.
5. Under Font Style, select Bold, and click OK.
6. Leave the Find what text box empty, and in the Replace with text box,
type the following:
<bold>^&</bold>
7. Click Replace All.
For italic text:
1. Press Ctrl+H to open the Find and Replace dialog box.
2. Click No Formatting.
3. Click Formatting.
4. Click Font.
5. Under Font Style, select Italic, and click OK.
6. Leave the Find what text box empty, and in the Replace with text box,
type the following:
<italic>^&</italic>
7. Click Replace All.
After you finish, perform the following steps to enable Word to find
unformatted text.
1. In the expanded Find and Replace dialog box, click the No Formatting
button.
2. Click Less.
3. Perform a new search before closing the Find and Replace dialog box.
Note that these procedures will add the tags that you want, but they will
not clear the font formatting. If you want to clear all the font formatting
in your document, you can press Ctrl+A and then Ctrl+Spacebar.
--
Hope this helps,
Pesach Shelnitz
My Web site:
http://makeofficework.com
:
Is it possible to find [boldtext] [italictext] and replace with
<bold>boldtext</bold> <italic>italictext</italic> in MS Word using regular
expressions?
[boldtext] [normaltext] [italictext] should remain undisturbed, I only need
to change [boldtext] [italictext] format.
Please help, thanks in advance, raj