Results 1 to 4 of 4

Excel VBA to open new outlook message with signature and preferred body text format

Threaded View

  1. #1
    Registered User
    Join Date
    10-31-2011
    Location
    Singapore
    MS-Off Ver
    Microsoft 365 (Windows 10)
    Posts
    67

    Excel VBA to open new outlook message with signature and preferred body text format

    Hi,

    I use an excellent VBA macro from Ron de Bruin to copy and paste a range of cells into the body of an outlook email. It works a breeze, and i'm very happy with it. However, the new mail window this macro opens has Time New Roman as the default font and i would like Calibri, size 11. This new mail woindow also doesnt have my new message signature, and im having to follow the steps in outlook to insert the signature every time i send the mail. Is there a way to tweaqk the code below so that:

    1. Text format of the new mail message is Calibri, size 11.
    2. The new mail widow contains my signature as it would if i opened a new mail widow from within Outlook



    Currently, the excel range goes into the email and i manually change everything, but i have to send many of these mails a day so i was hoping it could have it programmed to my preferences to make life a little easier..!

    Here is the macro I use. Appreciate any help! Thanks

    -----

    Sub ***()
    
    
        Selection.EntireRow.Hidden = False
        Range("B2:L15").Select
    
        Dim rng As Range
        Dim OutApp As Object
        Dim OutMail As Object
    
        Set rng = Nothing
        On Error Resume Next
      
        Set rng = Selection.SpecialCells(xlCellTypeVisible)
    
        On Error GoTo 0
    
        If rng Is Nothing Then
            MsgBox "The selection is not a range or the sheet is protected" & _
                   vbNewLine & "please correct and try again.", vbOKOnly
            Exit Sub
        End If
    
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        On Error Resume Next
        With OutMail
            .To = "***"
            .CC = "***"
            .BCC = ""
            .Subject = "***"
            .HTMLBody = RangetoHTML(rng)
            .Display
        End With
        On Error GoTo 0
    
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    
    
    Function RangetoHTML(rng As Range)
    
        Dim fso As Object
        Dim ts As Object
        Dim TempFile As String
        Dim TempWB As Workbook
    
        TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
    
      
        rng.Copy
        Set TempWB = Workbooks.Add(1)
        With TempWB.Sheets(1)
            .Cells(1).PasteSpecial Paste:=8
            .Cells(1).PasteSpecial xlPasteValues, , False, False
            .Cells(1).PasteSpecial xlPasteFormats, , False, False
            .Cells(1).Select
            Application.CutCopyMode = False
            On Error Resume Next
            .DrawingObjects.Visible = True
            .DrawingObjects.Delete
            On Error GoTo 0
        End With
    
     
        With TempWB.PublishObjects.Add( _
             SourceType:=xlSourceRange, _
             Filename:=TempFile, _
             Sheet:=TempWB.Sheets(1).Name, _
             Source:=TempWB.Sheets(1).UsedRange.Address, _
             HtmlType:=xlHtmlStatic)
            .Publish (True)
        End With
    
     
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
        RangetoHTML = ts.readall
        ts.Close
        RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                              "align=left x:publishsource=")
    
      
        TempWB.Close savechanges:=False
    
      
        Kill TempFile
    
        Set ts = Nothing
        Set fso = Nothing
        Set TempWB = Nothing
    End Function
    Last edited by morayman; 11-06-2013 at 10:16 PM. Reason: I broke the rules!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Create Outlook Reminder on Excel and transfered to outlook by macro
    By Benjamin2008 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2013, 03:23 PM
  2. [SOLVED] VBA Macro to print to Pdf format and place as attachment in Outlook (Excel & Outlook 2007)
    By Webman1012 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2013, 01:25 PM
  3. Export from Excel to Outlook, Outlook has to be running?
    By christian2012 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2013, 07:01 PM
  4. Exporting Excel data into Outlook calendars: Changing an Outlook VBA to Excel VBA
    By spaceporker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-19-2012, 11:39 PM
  5. excel open in outlook if outlook is running
    By kirk in forum Excel General
    Replies: 0
    Last Post: 05-24-2006, 01:45 PM

Tags for this Thread

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