PDA

View Full Version : [SOLVED:] VBA for replace Font with specific Text



romiljpr
04-22-2021, 08:54 AM
Hi,
I want to replace specific text font name to other font name. I am trying to write a macro for it. but font name not working here. please help and give a suggestion for it. sorry for bad grammer.


Sub ReplaceTextWithFormatting()

For Each myStoryRange In ActiveDocument.StoryRanges
With myStoryRange.Find

.ClearFormatting
.Text = "wiki"
.Font.Name = "Arial"
.Replacement.ClearFormatting
.Replacement.Text = "Romil"
.Wrap = wdFindContinue
.MatchCase = True
.MatchWholeWord = True
.ClearFormatting
.Replacement.Font.Name = "Kokila"
.Replacement.Font.Bold = True
.Replacement.Font.Size = 18
.Replacement.Font.Subscript = True
.Replacement.Font.Color = RGB(0, 0, 255)
.Execute Replace:=wdReplaceAll

End With

Next myStoryRange

End Sub

macropod
04-22-2021, 02:26 PM
Replace your " expressions with actual plain double-quotes.

You should also specify:
.Format = True

PS: When posting code, please usethe code tags, indicated by the # button on the posting menu. Without them,your code loses much of whatever structure it had.

romiljpr
04-22-2021, 06:08 PM
Replace your " expressions with actual plain double-quotes.

You should also specify:
.Format = True

PS: When posting code, please usethe code tags, indicated by the # button on the posting menu. Without them,your code loses much of whatever structure it had.

Thanks a lot
It work.