Recreating a WORD Editing Macro to use in Outlook VBA

Status
Not open for further replies.

Philip Rose

New Member
Outlook version
Email Account
Exchange Server 2007
Hello,
This is a simple VBA macro which I wrote to use in Word 2007. It addresses the problem of long sentences. The macro operates by replacing the first character in the selected text with a full stop and the last character is raised to a capital letter. Everything between these two is deleted and replaced with a double space.

Sub MakeSentance()
Dim FirstChar, LastChar, NewString As String

FirstChar = Left(Selection, 1)
LastChar = UCase(Right(Selection, 1))

NewString = FirstChar & ". " & LastChar

Selection = NewString

End Sub


The macro works perfectly in Word 2007 and I would like to be able to use it when I am composing an email (Outlook 2007). Unfortunately I cannot work out how to alter this code so that I can run it in inspector, mode to edit the text that I have highlighted/selected. What I need to know is…

  1. How do I set the code to operate with the email that I am creating?
  2. How do I acquire the selected ('Selection') text?
  3. When I have made the alterations, how do I 'put back' the new version of the selection?

I imagine that the answer to these questions is stunningly obvious but I have been unable to discover it for myself and for that reason I thank you in anticipation of your help.

Philip
 
I didn't test this in outlook 2007, but see if this works - it works in outlook 2013, but I'm not sure i see the utility in it (maybe that is because it's not working like it does in 2007. :))


Code:
  Public Sub FormatSelectedText()
    Dim objItem As Object
    Dim objInsp As Outlook.Inspector
      Dim FirstChar, LastChar, NewString As String

    ' Add reference to Word library
    ' in VBA Editor, Tools, References
    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    On Error Resume Next
   
'Reference the current Outlook item
    Set objItem = Application.ActiveInspector.CurrentItem
    If Not objItem Is Nothing Then
        If objItem.Class = olMail Then
            Set objInsp = objItem.GetInspector
            If objInsp.EditorType = olEditorWord Then
                Set objDoc = objInsp.WordEditor
                Set objWord = objDoc.Application
                Set objSel = objWord.Selection

' your code goes here

FirstChar = Left(objSel, 1)
LastChar = UCase(Right(Selection, 1))
NewString = FirstChar & ". " & LastChar
objSel = NewString


            End If
        End If
    End If
    
    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing
End Sub
 
Dear Diane,
Thank you so much for your helpful response. As I'm sure you appreciate, I'm not just trying to create this simple macro but I am really trying to learn the techniques within Outlook.

The code you sent me does make sense (ish). I think I can follow it however when I try to run the code I get a compiler errors. On the dim statement for the Word.Application assignment.

Perhaps this object is not available in Outlook 2007?. We are currently trying to decide whether we should upgrade to the latest Office version or to switch over to Office 365. We are going to do one or the other and perhaps I should wait until then to have a look again at creating the macro?

Once again thank you for your help. I will keep in touch

Philip
 
Did you see this:
' Add reference to Word library
' in VBA Editor, Tools, References

In the VBA Editor, go to Tools, References and find the word object model. That will fix the error.

As an office 365 enterprise customer, I think office 365 is great... but your macro should work with 2007 once you set the reference. :)
 
Everyday is a school day!

Diane, thank you so much. I have got it working and I am learning so much!

Thanks again!

Philip
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
N pst files are recreating automaticaly and cannot be deleted Using Outlook 5
S Outlook 2021 Can you make emails from 3 word domains "safe" by entering top 2 word domain into Safe List in Outlook? Using Outlook 1
O How to find and replace a word in Outlook-Agenda-Subject and Message? Using Outlook 0
V Embedding hyperlink into Word document Using Outlook 2
glnz Can Word Normal.dotm interfere with Outlook? Office 2016 Using Outlook 5
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
C blocking two or more word domains separated by period/dot Using Outlook 3
P Outlook 2013 Word Share doc as Email Attachment now brings up Eudora. Using Outlook 1
Jennifer Murphy Ctrl+Tab sometimes will not move through text a word at a time Using Outlook 1
N How to remove signature formatting from Text in Word (accidentally taken from Outlook) Using Outlook 0
C replace subject line generated by converting a word document to PDF and sending it to an email Using Outlook 8
Diane Poremsky Use Word Macro to Apply Formatting to Email Using Outlook 0
iwshim word shortcut to search outlook Using Outlook 3
C Outlook 2016 - converting Word VBA to default Outlook message Outlook VBA and Custom Forms 0
C Merging Word and Access into Outlook Using Outlook 4
Q Why can't I copy image with embedded hyperlink from email to Word Using Outlook 0
Mark Foley Emailing attachment from Word/Excel sends attachment but no message body Using Outlook 0
Diane Poremsky Disable Live Preview in Outlook and Word Using Outlook 0
D Need to extract a line from a word attachment, and add it to the subject line Outlook VBA and Custom Forms 3
M Unable to email from Word or Excel Using Outlook 11
P Macros in Word 2003 - how to transfer to another Word 2003? Using Outlook 1
J VBS Script (macro) for word to open Outlook template. Outlook VBA and Custom Forms 2
B Outlook to Word Template error Using Outlook 4
J Outlook body to word document Outlook VBA and Custom Forms 11
A Is it possible to remove the word Categories: from task list views? Using Outlook 2
A Application_ItemSend not accessed when sending email outside outlook (i.e. word or send to mail from Using Outlook 7
W Macro to add a word in Subject Line Using Outlook 1
O Copy email content and paste into new Word Document using a different font Using Outlook 1
K Import 2013 Outlook Contact Address into Word Using Outlook 36
J "Specific word in body" question Using Outlook 1
D opening Word Document in a business contact? BCM (Business Contact Manager) 3
Z Send mail and contents of body from ms word document Using Outlook 1
O Choosing Sending Email Address from Word Using Outlook 5
C Printing Outlook Form Controls via Word Using Outlook 11
S Highlighter colors limited in Outlook 2007 and Word 2007 Using Outlook 1
L Macro to Open a Specific Word Document - Outlook 2007 Using Outlook 17
O Outlook 2010 does not open MS Word attachments Using Outlook 1
R Using Word/OL 2010 to generate personalized email messages Using Outlook 1
S send email attachment from word, message stripped out Using Outlook 1
M Opening Word Doc's in Adobe Acrobat Pro Using Outlook 9
D Word Wrap Subject Using Outlook 1
C Outlook editing won't select just one word Using Outlook 1
B MS Office 2010: Word email merge not selecting default Outlook account Using Outlook 1
T Word attached files open Word. Excel files open Picture Manager!! Using Outlook 2
C Outlook 2010 some messages received have no word wrap Using Outlook 1
G No word wrap in HTML email. Using Outlook 8
P Word experienced and error trying to open the file Using Outlook 2
T New Inspector word editor crash Outlook 2003 Outlook VBA and Custom Forms 3
T Word 2007 add-in ribbon icons greyed out Outlook VBA and Custom Forms 1
G BCM Word Add-In BCM (Business Contact Manager) 1

Similar threads

Back
Top