Running multiple macros in Outlook

Holley

Board Regular
Joined
Dec 11, 2019
Messages
156
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello all! Checking here as I have had no response from another board I visit... Not Excel but still Microsoft related and hoping to find some help here as I have in the past.

In Outlook, I have two macros that I would like to combine into a single step. Macro 1is opens an email template, paste the clipboard contentes. Macro 2
Hello all! I have two macros that I would like to combine into a single step. Macro 1is opens a template, paste the clipboard contentes into the body of the template. Macro 2 opens an email template, paste teh clipboard contents into the body of the email and cuts the email address from the body of email and paste it into the To field of the email. Each of these work great individually, but I cannot even do a simple "call" for these two to work together. Any suggestions?

One other tweak I would like to make is for it to copy the Customer # and past it within the subject line of the email, but if that never happens, if I could just get the first two to work together, that would be be most appreciated!

I would greatly appreciate any suggestions!

This is the two codes:
Macro 1
VBA Code:
Dim MyItem As Outlook.MailItem
Dim str_jpeg_file As String

Dim wdDoc As Object
Dim oRng As Object
    
    'On Error Resume Next
    Set OutApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then Set OutApp = CreateObject("Outlook.Application")
    On Error GoTo 0
    
    'Set OutMail = OutApp.CreateItem(0)
    Set MyItem = Application.CreateItemFromTemplate("C:\Users\user2\Documents\Customer Statement .msg")
    MyItem.Display
    With MyItem
        .BodyFormat = 2
       ' .To = ""
       ' .CC = ""
        '.BCC = ""
        .Subject = "Customer Statement "

SendKeys "{right}{down}^({v})", True
End With
End Sub

Macro 2

VBA Code:
Sub ReadMsg2()
'Graham Mayor - https://www.gmayor.com - Last updated - 06 Jul 2024
Dim olMsg As MailItem
    On Error Resume Next
    Select Case Outlook.Application.ActiveWindow.Class
        Case olInspector
            Set olMsg = ActiveInspector.CurrentItem
        Case olExplorer
            Set olMsg = Application.ActiveExplorer.Selection.Item(1)
    End Select
   GetAddress olMsg
lbl_Exit:
    Set olMsg = Nothing
    Exit Sub
End Sub
Sub GetAddress(olItem As MailItem)
Dim olInsp As Outlook.Inspector
Dim wdDoc As Object
Dim oRng As Object
Dim oAddr As Object
Dim hLink As Object
    With olItem
        Set olInsp = .GetInspector
        Set wdDoc = olInsp.WordEditor
        Set oRng = wdDoc.Range
        With oRng.Find
            Do While .Execute(findText:="Sincerely")
                Set oAddr = oRng
                Exit Do
            Loop
        End With
        If Not oAddr Is Nothing Then
            oAddr.collapse 1
            oAddr.MoveStartUntil "@", -1073741823
            Set oAddr = oAddr.Paragraphs(1).Range
            If Not oAddr Is Nothing Then
                olItem.To = oAddr.Text
                oAddr.Text = ""
            End If
        End If
    End With
lbl_Exit:
    Set olInsp = Nothing
    Set wdDoc = Nothing
    Set oRng = Nothing
    Set oAddr = Nothing
    Exit Sub
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,225,188
Messages
6,183,430
Members
453,160
Latest member
DaveM_26

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top