+ Reply to Thread
Results 1 to 3 of 3

Sending an Email to Unknown Supervisor

Hybrid View

  1. #1
    Registered User
    Join Date
    01-28-2014
    Location
    Merseyside, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Sending an Email to Unknown Supervisor

    Hi Everyone,

    I was wondering if it's possible to grab a supervisors Email address from the organization tab in outlook properties.
    I'm trying to write a macro for any user at work to click a button and current workbooks get sent to their supervisor.

    Any help would be appreciated.

    Cade
    Last edited by Cadelanne; 02-06-2014 at 07:35 AM.

  2. #2
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Re: Sending an Email to Unknown Supervisor

    try this (you would need to change "last name first name" for each of the users with their full name (last name first name format)
    also, before attaching the current file, it must be saved.

    Sub SendEmailToManager()
    
    On Error Resume Next
    Dim I As Integer
    
    Dim ToAddr As String
    Dim ActivePersonVerified As Boolean
    Dim ol As Outlook.Application
    Dim DummyEMail As MailItem
    Dim ActivePersonRecipient As Recipient
    Dim oAE As Outlook.AddressEntry
    Dim oExUser As Outlook.ExchangeUser
    Dim oPA As Outlook.PropertyAccessor
    Dim strManager As String
    
    'code taken from:
    'http://social.msdn.microsoft.com/Forums/office/en-US/183a9b77-7f5a-4afc-91e6-fbe2914c5f78/extract-data-from-the-global-address-book-with-vba?forum=outlookdev
    
    'Instantiate Outlook
    
    Set ol = CreateObject("Outlook.Application")
    'E-mail aliases are in a named range "aliasrange"
    'Assign the named range to a range object
    
    'Create a dummy e-mail to add aliases to
    
    Set DummyEMail = ol.CreateItem(olMailItem)
    
        'Assign the current alias to a variable ToAddr
        ToAddr = "last name first name" ' enter the user's name
        'Use the alias to create a recipient object and add it to the dummy e-mail
    
        Set ActivePersonRecipient = DummyEMail.Recipients.Add(ToAddr)
        ActivePersonRecipient.Type = olTo
        'Resolve the recipient to ensure it is valid
    
        ActivePersonVerified = ActivePersonRecipient.Resolve
        'If valid, use the  AddressEntry property of the recipient to return an AddressEntry object
    
        If ActivePersonVerified Then
            Set oAE = ActivePersonRecipient.AddressEntry
            'Use the GetExchangeUser method of the AddressEntry object to retrieve the ExchangeUser object for the recipient.
    
            Set oExUser = oAE.GetExchangeUser
            'Write the properties of the  ExchangeUser object to adjacent columns on the worksheet.
    
            ActivePersonRecipient.Delete
            'Remove the recipient from the e-mail
            
            ToAddr = oExUser.Manager
            Set ActivePersonRecipient = DummyEMail.Recipients.Add(ToAddr)
            
                ActivePersonRecipient.Type = olTo
                'Resolve the recipient to ensure it is valid
            
                ActivePersonVerified = ActivePersonRecipient.Resolve
                
                Set oAE = ActivePersonRecipient.AddressEntry
                Set oExUser = oAE.GetExchangeUser
                
                ToAddr = oExUser.PrimarySmtpAddress
        End If
        
        DummyEMail.Display
        DummyEMail.Subject = "for my manager"
        DummyEMail.Body = "please review the attachment"
        DummyEMail.Attachments.Add ActiveWorkbook.FullName
        
        
    ExitOutlookEmail:
    
        Set DummyEMail = Nothing
    
        Set ol = Nothing
    
    End Sub
    Click on the star if you think I helped you

  3. #3
    Registered User
    Join Date
    01-28-2014
    Location
    Merseyside, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Sending an Email to Unknown Supervisor

    Thanks Ady,

    I like to read through and understand everything thats going into VBA. I've been busy at work so haven't had the time to properly look at this.
    Works for me .

    Cade

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. automation/macro for sending email to multiple email address
    By saurabhlotankar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-30-2013, 12:13 PM
  2. Sending HTML email via excel VBA - arriving as RTF email
    By Shuter1 in forum Outlook Programming / VBA / Macros
    Replies: 3
    Last Post: 06-21-2012, 04:35 AM
  3. Sending Email Dependent on Default Email Client
    By Julesdude in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-30-2010, 06:51 AM
  4. Sending an email from Excel to multiple email addresses
    By insanity66 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-14-2009, 02:01 PM
  5. Sending email using users preferred email client
    By deadlyduck in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2009, 06:29 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1