bcn
12-07-2012, 01:41 AM
Hi,
I'm having a hard time trying to write this macro. I think I'm taking the long way and I still cannot figure out how to loop it. Any help will be highly appreciated!
What I want to do
I have a huge document full of button names that are in small caps and enclosed in » «. They look like this:
Click »OK«. (Where "OK" is in small caps.)
To import the data, click »Import« (Where "Import" is in small caps.)
Since some of the button names may not have the small caps format applied to them, I want the macro to look for all strings enclosed in » and « and:
1. Change the » to CharacterNumber:=-3971, Font:="Wingdings 3", Unicode:=True and the « to CharacterNumber:=-3972, Font:="Wingdings 3", Unicode:=True
2. Apply a style called "Button" to the string and the two special characters.
3. Loop it (make the macro find all the cases and process them throughout the document).
What I have so far is:
Sub LSreplaceOldButtonStyle()
Dim oRng As Word.Range
Dim text As String
Selection.Find.ClearFormatting
With Selection.Find
.text = "»"
.Replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.InsertSymbol CharacterNumber:=-3971, Font:="Wingdings 3", Unicode:=True
Selection.Find.ClearFormatting
With Selection.Find
.text = "«"
.Replacement.text = ""
.Forward = True
.Wrap = wdFindAsk
End With
Selection.Find.Execute
Selection.InsertSymbol CharacterNumber:=-3972, Font:="Wingdings 3", Unicode:=True
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.text = ChrW(-3971)
.Replacement.text = ""
.Forward = False
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.Style = ActiveDocument.Styles("Button")
Thanks a lot!
Daniel
I'm having a hard time trying to write this macro. I think I'm taking the long way and I still cannot figure out how to loop it. Any help will be highly appreciated!
What I want to do
I have a huge document full of button names that are in small caps and enclosed in » «. They look like this:
Click »OK«. (Where "OK" is in small caps.)
To import the data, click »Import« (Where "Import" is in small caps.)
Since some of the button names may not have the small caps format applied to them, I want the macro to look for all strings enclosed in » and « and:
1. Change the » to CharacterNumber:=-3971, Font:="Wingdings 3", Unicode:=True and the « to CharacterNumber:=-3972, Font:="Wingdings 3", Unicode:=True
2. Apply a style called "Button" to the string and the two special characters.
3. Loop it (make the macro find all the cases and process them throughout the document).
What I have so far is:
Sub LSreplaceOldButtonStyle()
Dim oRng As Word.Range
Dim text As String
Selection.Find.ClearFormatting
With Selection.Find
.text = "»"
.Replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.InsertSymbol CharacterNumber:=-3971, Font:="Wingdings 3", Unicode:=True
Selection.Find.ClearFormatting
With Selection.Find
.text = "«"
.Replacement.text = ""
.Forward = True
.Wrap = wdFindAsk
End With
Selection.Find.Execute
Selection.InsertSymbol CharacterNumber:=-3972, Font:="Wingdings 3", Unicode:=True
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.text = ChrW(-3971)
.Replacement.text = ""
.Forward = False
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.Style = ActiveDocument.Styles("Button")
Thanks a lot!
Daniel