View Single Post
 
Old 04-21-2022, 07:51 PM
trevorc trevorc is offline Windows 7 32bit Office 2013
Competent Performer
 
Join Date: Jan 2017
Posts: 174
trevorc will become famous soon enoughtrevorc will become famous soon enough
Default VBA code looks ugly, but works ok, needs a going over to neaten it up.

Hi All,
Just started dipping into VBA for Outlook, have been using it for Excel and Access for some time.
I managed to put together this code from several places and it works ok, but looks like a mess of bits. Is there an easier/neater way to write this.

Code:
Sub SendMailItem()           ' Send email to remove from hold selected RMA by Number
    Dim item As Outlook.MailItem
    Dim sct As Outlook.Selection
    Dim byt As Byte
    Dim OutApp As Object
    Dim outmail As Object
    Dim msgbody As String
    Dim objol, objmsg, objforward, objOrignialBody, objsubject
    Dim myInspector As Outlook.Inspector
    Dim myItem As Outlook.MailItem
    Set OutApp = CreateObject("Outlook.Application")
    Set sct = Application.ActiveExplorer.Selection
    Set item = sct(1)
          item.Display
    Set outmail = OutApp.ActiveInspector.CurrentItem
    Set myInspector = Application.ActiveInspector
    Set myItem = myInspector.CurrentItem
    Set objol = CreateObject("Outlook.Application")
    Set objmsg = objol.ActiveInspector.CurrentItem
    Set objforward = objmsg.Forward
    msgbody = outmail.Body
    outmail.Body = "Thankyou." & vbNewLine & vbNewLine & vbNewLine & msgbody
    objforward.Recipients.Add "t@.com.au" '"t@.com.au"
    objOrignialBody = objforward.Body
DraftEmail:
    objforward.Subject = "Re: " & objforward.Subject
    objforward.Body = "Thankyou " & objforward.Body
objforward.Display
'objforward.Send
    Set outmail = Nothing
    Set OutApp = Nothing
    myItem.Close olSave
End Sub
Reply With Quote