Insert paragraph before a capital letter - word VBA - 6 lines of code

makiwara

Board Regular
Joined
Mar 8, 2018
Messages
171
Something is missing and I can't figure it out. VBA editor highlights error at this line: Mid(MyString, Counter-1, 1).Paragraphs.Add
and I don't know how could I achieve what I need.

Basically I have to loop through every paragraph and examine the first character of it. For example there will be a pharagraph:

'the show must Go on

And I need to insert a new paragraph before "G", so:

'the show must
Go on

What am I missing?

VBA Code:
For Each para In ActiveDocument.Paragraphs

    If para.Range.Font.Size = 12 Then
 
                Txt = para.Range.Text

                If Left(Txt, 1) = "'" Then

                         For Counter = 1 To Len(Txt)
         

                               If Mid(MyString, Counter, 1) = UCase(Mid(MyString, Counter, 1)) Then

                               'SOMETHING IS WRONG HERE
                                Mid(MyString, Counter-1, 1).Paragraphs.Add

                                End If


                         Next

                End If
 
               
 
 
    End If

    Next
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Even if you were to get your code working, it is extremely inefficient. Try:
VBA Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .Font.Size = 12
  .Execute FindText:="([!^13A-Z])([A-Z])", ReplaceWith:="\1^p\2", MatchWildcards:=True, Format:=True, Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
OK, Mr. Paul (retired moderator). You are on top of your game.
 
Upvote 0

Forum statistics

Threads
1,223,641
Messages
6,173,506
Members
452,518
Latest member
SoerenB

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top