Formatting text received in E-Mail

Getting the macro on

First of all, open a new text document with Word.

Create a new macro and put this piece of code in it:

Sub adecuaFrases()
' Adecúa las frases de todo el documento. (Reformat all sentences in document)
'   -Elimina los espacios iniciales y finales. (Deletes pre and post extra spacing)
'   -Elimina el caracter '>' debidos a E-Mail (Deletes '> character due to E-Mail fwd)
Dim i As Long
   i = 1
   Do Until i > ActiveDocument.Sentences.Count
       With ActiveDocument.Sentences(i).Characters
           Select Case .First
           Case ebcAttach
               '->Eliminar la primera letra. (delete first character)
           Case Is <> UCase(.First)
               'La primera letra es minuscula (If first letter is lowercase)
               '->Eliminar el retorno de carro anterior. (delete carriage return)
               Selection.Start = ActiveDocument.Sentences(i).Start
               Selection.MoveLeft 1, wdCharacter
               If Selection.Text = "." Then Selection.TypeText ","
               Selection.TypeText ebcEspacio
           Case Else
               'Nada (do nothing)
               i = i + 1
           End Select
       End With
End Sub

Excuse me if the name of the macro and all the coments are in Spanish. I'm afraid it's my native language. :)

'FOOTNOTE by moderator. I don't speak a single word spanish, except perhaps Yo qiero Taco Bell.
'but I attempted to make a few english comments out of it anyway.
Back to the matter, you will need also this sub:

Sub trimSentences()
Dim i As Integer
   i = 1
   Do While i <= ActiveDocument.Sentences.Count
       ActiveDocument.Sentences(i).Text = Trim(ActiveDocument.Sentences(i).Text)
       i = i + 1
End Sub

And that's all!!! The macro is ready to be tested. Just paste some text you may have received and launch the macro!

I hope you find useful this little macro. I did.
All sugestions will be welcome,
     Carlos Iván

You might also like...


Carlos Ivan Conde Martin


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov