Forum Discussion

JessicaBenou's avatar
JessicaBenou
Copper Contributor
Mar 24, 2026

VBA: Why does an enter appear at the end of my document?

Hello

I have a VBA-code which - when used - always places an enter at the end of my document and I can't find out why.

Can someone help me with this?

This is the code:

Sub TekstNaarInvulruimteBlauw()

'

' TekstNaarInvulruimteBlauw Macro

'

'

Selection.Find.ClearFormatting

Selection.Find.Replacement.ClearFormatting

Selection.Find.Replacement.Font.Color = wdColorAutomatic

With Selection.Find

.Text = "^p"

.Replacement.Text = "^p"

.Forward = True

.Wrap = wdFindContinue

.Format = True

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find

.Text = "^l"

.Replacement.Text = "^l"

.Forward = True

.Wrap = wdFindContinue

.Format = True

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find

.Text = "- "

.Replacement.Text = "- "

.Forward = True

.Wrap = wdFindContinue

.Format = True

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find

.Text = "(?...?)"

.Replacement.Text = "###"

.Forward = True

.Wrap = wdFindContinue

.Format = True

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find

.Text = "(?...?X)"

.Replacement.Text = "###"

.Forward = True

.Wrap = wdFindContinue

.Format = True

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting

Selection.Find.Font.Color = wdColorBlue

Selection.Find.Replacement.ClearFormatting

Selection.Find.Replacement.Font.Color = wdColorBlue

With Selection.Find

.Text = ""

.Replacement.Text = "?...?"

.Forward = True

.Wrap = wdFindContinue

.Format = True

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting

Selection.Find.Replacement.ClearFormatting

Selection.Find.Replacement.Font.Color = wdColorBlue

With Selection.Find

.Text = "###"

.Replacement.Text = "(?...?)"

.Forward = True

.Wrap = wdFindContinue

.Format = True

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute Replace:=wdReplaceAll

Selection.HomeKey Unit:=wdStory

End Sub

 

 

Many thanks in advance.

Jessica

2 Replies

  • JessicaBenou's avatar
    JessicaBenou
    Copper Contributor

    My question is already answered at 

    https://learn.microsoft.com/en-us/answers/questions/5834907/vba-why-does-an-enter-appear-at-the-end-of-my-docu?page=1