-
Solved: can't remove carriage return
I often copy and paste text into an email. Sometimes each line has a carriage return (CR) which terminates the line. How does the script look like that would delete all CRs in a selected paragraph of text?
In Word I use the following script. It does not work in Outlook.
[VBA]Sub DeleteCR()
With Selection
.Text = Replace(.Text, vbCr, " ")
End With
End Sub[/VBA]
In PowerPoint I use another script. That also doesn't work in Outlook.
[VBA]Sub DeleteCRs()
Dim oshp As Shape
Dim otxt As TextRange
'check for type of selection
'replaces all text in shape unless
'text is highlighted
If ActiveWindow.Selection.Type = ppSelectionNone _
Or ActiveWindow.Selection.Type = ppSelectionSlides Then Exit Sub
If ActiveWindow.Selection.Type = ppSelectionShapes Then
Set oshp = ActiveWindow.Selection.ShapeRange(1)
Set otxt = oshp.TextFrame.TextRange
End If
If ActiveWindow.Selection.Type = ppSelectionText Then
Set otxt = ActiveWindow.Selection.TextRange
If Len(otxt) < 1 Then
Set otxt = otxt.Parent.Parent.TextFrame.TextRange
End If
End If
With otxt
.Text = Replace(.Text, vbCr, " ")
End With
With otxt
.Text = Replace(.Text, ". ", ". " & vbCr)
End With
End Sub[/VBA]
-
[VBA]Sub use_selection_of_text_in_body()
'The mail is open and a selection is made before
'running this macro !!!
'themessage is the word editor we are going to use
Dim themessage As Object
'is the selection of the mailbody
Dim mydoc As Object
'the string of the selection
Dim mytext As String
'create the word editor
Set themessage = Application.ActiveInspector.WordEditor
'print to debug window (ctrl+g to display it)
Debug.Print themessage
'get the selection of text
Set mydoc = themessage.windows(1).Selection
'print to debug window
Debug.Print mydoc
'store mydoc to string variable
'if format needs to be retained, maybe look for
'search and replace stuff in word
mytext = mydoc.Text
'use replace to get rid of enter
mytext = Replace(mytext, vbCr, "")
'print to debug window
Debug.Print mytext
'get new text into message.
'note : original format (lettertype, formatting, ...) is lost
themessage.windows(1).Selection = mytext
End Sub[/VBA]Charlize
-
great! That is working. Thanks Charlize.
Now, I just need to figure out how to turn this macro into an add-in.
That is, if that is possible at all in Outlook.
-
Just fire up a copy of VB6 and you can turn the code into an addin.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules