Consulting

Results 1 to 3 of 3

Thread: Insert Logo (image) on draft emails VBA

  1. #1

    Insert Logo (image) on draft emails VBA

    Hi,

    I have bunch of emails (around 50 emails) sitting on draft folder and I would like to embed a logo to all emails which is saved to my documents. The logo should be on the top left side of the body email. I am not very knowledgeable with VBA so I hope someone can help me with the codes.

    Thanks.

  2. #2
    For the future it might make more sense to create stationery or a signature with your logo, however the following should work. Change the path of the logo ("D:\My Documents\My Pictures\GMLogo.png") to the path of the logo you wish to use.

    Sub AddLogo()
    'Graham Mayor - http://www.gmayor.com - Last updated - 20 Sep 2017
    Dim olFolder As Outlook.Folder
    Dim olItems As Outlook.Items
    Dim olItem As Outlook.MailItem
    Dim olInsp As Outlook.Inspector
    Dim wdDoc As Object
    Dim oRng As Object
    Dim oShape As Object
    
    Dim i As Long
        On Error Resume Next
        Set olFolder = Session.GetDefaultFolder(olFolderDrafts)
        Set olItems = olFolder.Items
        For i = olItems.Count To 1 Step -1
            Set olItem = olItems(i)
            With olItem
                .BodyFormat = olFormatHTML
                Set olInsp = .GetInspector
                Set wdDoc = olInsp.WordEditor
                .Display
                Set oRng = wdDoc.Range(0, 0)
                Set oShape = oRng.InlineShapes.AddPicture _
                             (fileName:="D:\My Documents\My Pictures\GMLogo.png", _
                              LinkToFile:=False, _
                              SaveWithDocument:=True)
                Set oRng = oShape.Range
                oRng.collapse 0
                oRng.Text = vbCr
                .Save
                .Close 1
            End With
        Next i
    
    lbl_Exit:
        Set olFolder = Nothing
        Set olItems = Nothing
        Set olItem = Nothing
        Set olInsp = Nothing
        Set wdDoc = Nothing
        Set oRng = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Thanks. It works perfectly

Posting Permissions

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