- Joined
- Aug 12, 2022
- Messages
- 6
- Reaction score
- 0
What I am trying to do: I tried to write a macro that pastes a string then selects that string and applies a style to it.
So Record Macro
select desired style
paste
type comma and space
select Normal style
No. The desired style does not apply to the pasted text. F8 to extend before applying style does not work.
So I next wrote the macro to:
type \
paste text
Find \
Click on found item (there is only one match)
Close Find tab
delete \
F8
Find Paragraph ^p
apply style
Type , blank
Apply Normal
The VBA is:
Sub newspaperTitle()
'
' newspaperTitle Macro
'
'
Selection.TypeText Text:="\"
Selection.PasteAndFormat (wdFormatOriginalFormatting)
With Selection.Find
.Text = ""
CommandBars("Navigation").Visible = False
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub
What am I doing wrong? I see no ApplyStyle in the VBA.
So Record Macro
select desired style
paste
type comma and space
select Normal style
No. The desired style does not apply to the pasted text. F8 to extend before applying style does not work.
So I next wrote the macro to:
type \
paste text
Find \
Click on found item (there is only one match)
Close Find tab
delete \
F8
Find Paragraph ^p
apply style
Type , blank
Apply Normal
The VBA is:
Sub newspaperTitle()
'
' newspaperTitle Macro
'
'
Selection.TypeText Text:="\"
Selection.PasteAndFormat (wdFormatOriginalFormatting)
With Selection.Find
.Text = ""
CommandBars("Navigation").Visible = False
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub
What am I doing wrong? I see no ApplyStyle in the VBA.