# How to create a macro that will "Enter" after each semicolon in a MS Word Doc?



## kingjoshdude81 (Jul 17, 2008)

*How to create a macro that will "Enter" after each semicolon in a MS Word Doc?*

Hey everyone! First post, but I am a long time lurker of the forums here. EXCELLENT information!!

I have a 400 page MS Word document filled with email addresses separated by a semicolon. I place the mouse cursor after each semicolon, press enter, and the email address hyperlinks as rest of the email addresses move down. I'm tryiing to get a single column of hyperlinked email addresses that i can copy into excel for future use.

It looks like this:

emailaddress;emailaddress;emailaddress;emailaddress;emailaddress;emailaddress;emailaddress;emailaddress;emailaddress;emailaddress;emailaddress;emailaddress;

When I manually do what I have described above it looks like this:

*emailaddress;*
*emailaddress;*
*emailaddress;*
*emailaddress;*

Any ideas for a macro that can locate every semicolon and press the "enter" key form me while hyperlinking? 

Thanks guys,Josh


----------



## David M58 (May 20, 2008)

*Re: How to create a macro that will "Enter" after each semicolon in a MS Word Doc?*

You may find this code useful, even if it isn't very pretty. It was thrown together rather quickly and probably could use some more tweaking and testing.


```
Sub sep()
    Dim dfind As Boolean
    Do
        ActiveDocument.Content.Select
        dfind = False
        Selection.Find.Execute FindText:=";", Forward:=True
        If Selection.Find.Found = True Then
            dfind = True
            Selection.TypeParagraph
            Selection.MoveUp wdLine, 1
            Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
            Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
            ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
                Address:="mailto:" & Selection.Text, _
                TextToDisplay:=Selection.Text
        End If
    Loop While dfind = True
End Sub
```
If the Word document contains only e-mail addresses separated by semicolons, and nothing else, and if this code works right, it should place each e-mail address on its own separate line. Modify as necessary.


----------



## kingjoshdude81 (Jul 17, 2008)

*Re: How to create a macro that will "Enter" after each semicolon in a MS Word Doc?*

David M58,

Thank you for your quick reply! The macro you provided is excellent!! Seems to work just fine for me. Brilliant!!

But, if I could have just one more birthday present this year I would ask you to either: 
A)Edit your macro to insert a semicolon at the end of each email address (the semicolon at the end of each is not included in the hyperlink and serves to seperate the email address "automatically" when multiple address are copied and pasted into the outlook recipient field.)

or, B)Design a new macro code that will insert the semicolons ad described above

I really suck at macros, and trying to accomplish this substantial task of sorting these email address doesn't allow any free time to experiment with the macros as I'd like.

You can see in the lead post the example of the semicolon at the end of each address. But in the word document the semicolon is not part of the hyperlink though it is placed directly after the address.

Thank you again David. your knowledge is invaluable!

-Josh


----------



## David M58 (May 20, 2008)

*Re: How to create a macro that will "Enter" after each semicolon in a MS Word Doc?*

How about this:

After running the macro, do a find and replace.
Find what: ^p
Replace with: ;^p


----------

