Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word

LinkBack Thread Tools Display Modes
Old 04-13-2019, 02:38 PM
Dent Dent is offline Windows 10 Office 2010
Join Date: Apr 2019
Posts: 1
Dent is on a distinguished road
Default How to insert colon at the start of every indentation


I want to insert colon after every indentation to an existing text.

My current text is like this:
JOHN Good morning!
JACK Good morning!

And I want it to be like this (with a command) because the existing text is very long to enter them manually, one by one.

JOHN : Good morning!
JACK : Good morning!

What do I need to do to insert colon in every line after second indentation?

Thank you in advance.
Reply With Quote
Old 04-13-2019, 09:10 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Join Date: Aug 2014
Posts: 2,705
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice

Based on insufficient information, the following will do what you ask. You will need to list the names used in the string strNames each separated by |. The code should only add the colons where they are not present (based on your message text).
Sub AddColons()
Dim VName As Variant
Dim oRng As Range
Dim oRng2 As Range
Dim i As Long
Const strNames As String = "JOHN|JACK"
    VName = Split(strNames, "|")
    For i = 0 To UBound(VName)
        Set oRng = ActiveDocument.Range
        With oRng.Find
            Do While .Execute(FindText:=VName(i), MatchWildcards:=True)
                If oRng.Start = oRng.Paragraphs(1).Range.Start Then
                    Set oRng2 = oRng.Duplicate
                    oRng2.End = oRng2.End + 2
                    If Not oRng2.Characters.Last = ":" Then
                        oRng.InsertAfter " :"
                    End If
                    oRng.Collapse 0
                 End If
        End With
    Next i
End Sub
Graham Mayor - MS MVP (Word)
Visit my web site for more programming tips and ready made processes
Reply With Quote
Old 04-16-2019, 03:11 AM
eNGiNe eNGiNe is offline Windows 7 32bit Office 2010 64bit
Join Date: Jan 2012
Location: Brussels [BE]
Posts: 700
eNGiNe is on a distinguished road

If this is a long text, something like a script or an extensive dialogue for role-play, perhaps you could consider setting up styles that insert the names as a prefix.
Reply With Quote

colon, indentation, insert

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Capitalization After Colon lowens Word 1 04-28-2018 02:58 PM
The difference between a comma and colon when adding? Exhale Excel 8 03-23-2016 05:26 AM
How remove colon ':' from my chapter references? peytontodd Word 6 01-28-2014 07:20 AM
Bullet Indentation Lost But Text Indentation Not Lost Trypsinogen Word 2 09-26-2013 02:01 PM
aligning colon JRaul Word 4 07-07-2012 06:06 AM

All times are GMT -7. The time now is 09:59 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc. is not affiliated with Microsoft