+ Reply to Thread
Results 1 to 12 of 12

Default signature at the end of email

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-19-2015
    Location
    India
    MS-Off Ver
    excel 2013
    Posts
    124

    Default signature at the end of email

    Hi I am using this code to automatically draft a email from excel but unable to get default signature.

    Please help me to get default signature at the end of email.

    Sub email()
    Dim mainWB As Workbook
    Dim SendID
    Dim CCID
    Dim Subject
    Dim Body
    Dim rng1 As Range
     
    Set otlApp = CreateObject("Outlook.Application")
    Set olMail = otlApp.CreateItem(olMailItem)
    Set Doc = olMail.GetInspector.WordEditor
    Set mainWB = ActiveWorkbook
    SendID = mainWB.Sheets("Product Report").Range("I20").Value
    CCID = mainWB.Sheets("Product Report").Range("I21").Value
    Subject = mainWB.Sheets("Product Report").Range("I22").Value
    Body = mainWB.Sheets("Screenshot").Range("A1:Z500").Value
    With olMail
        .To = SendID
        If CCID <> "" Then
          .CC = CCID
        End If
        .Subject = Subject
        mainWB.Sheets("Screenshot").Range("A1:Z500").Copy
        
        Set WrdRng = Doc.Range
        .Display
        WrdRng.Paste
        .Display
    End With
    Sheets("Product Report").Select
    
    End Sub

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Default signature at the end of email

    You can set your signature IN Outlook, you dont need VBA for that
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Contributor
    Join Date
    11-19-2015
    Location
    India
    MS-Off Ver
    excel 2013
    Posts
    124

    Re: Default signature at the end of email

    Hi Ford,

    Thank you for your reply!

    I have alrady set My signature in Outlook but when i run macro defalt signature did not polulate at the end of email.

    Regards,

    Xlhelp

  4. #4
    Forum Contributor
    Join Date
    11-19-2015
    Location
    India
    MS-Off Ver
    excel 2013
    Posts
    124

    Re: Default signature at the end of email

    Any update!

    Regards,

    Xlhelp7

  5. #5
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Default signature at the end of email

    You can set your default signature in your gmail account.
    in setting you will get the option.
    hth
    Sincerely,

    mso3

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Default signature at the end of email

    Quote Originally Posted by mso3 View Post
    You can set your default signature in your gmail account.
    in setting you will get the option.
    hth
    As far as I can tell, OP is using Outlook, not Gmail?

  7. #7
    Forum Contributor
    Join Date
    11-19-2015
    Location
    India
    MS-Off Ver
    excel 2013
    Posts
    124

    Re: Default signature at the end of email

    Hi Naveed

    Thanks for the reply!

    when i run you code it says variable not defined

    Regards,

    Xlhelp7

  8. #8
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Default signature at the end of email

    Quote Originally Posted by xlhelp7 View Post
    Hi Naveed

    Thanks for the reply!

    when i run you code it says variable not defined

    Regards,

    Xlhelp7
    hi,

    try this code

    Sub Email_VBA()
    Dim Wkb As Workbook: Set Wkb = ActiveWorkbook
    Dim ASht As Worksheet: Set ASht = Wkb.Sheets("Screenshot")
    Dim Rng As Range, Rw As Long, LC As Long, Rng2 As Range
    Dim SigString As String, Signature As String
    
    With ASht
        Set Rng = .Range("A1:Z500")
    End With
    Dim OApp As Object, OMail As Object, MyStr As Variant
    Set OApp = CreateObject("Outlook.Application")
    Set OMail = OApp.createitem(0)
    
    Subjct = Wkb.Sheets("Product Report").Range("I22").Value
    
    '======================================
    snm = "NAVEED" 'signature name which u have given in outlook
    SigString = Environ("appdata") & _
                    "\Microsoft\Signatures\" & snm & ".htm"
    If Dir(SigString) <> "" Then
        Signature = GetBoiler(SigString)
    Else
        Signature = ""
    End If
    '===================================
        With OMail
            .Display
            '.SentOnBehalfOfName = ""
            .To = Wkb.Sheets("Product Report").Range("I20").Value
            .CC = Wkb.Sheets("Product Report").Range("I21").Value
            .Subject = Subjct
            '"<P Style='Font-Family:Calibri;Font-Size:11'>"
            '.HTMLBody = strbody
            .HTMLBody = RangetoHTML(Rng) & "<BR>" & Signature
            '.send
        End With
    Set OMail = Nothing
    Set OApp = Nothing
    End Sub
    Function RangetoHTML(Rng As Range)
    Dim fso As Object, ts As Object
    Dim TempFile As String, 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
            '.Columns.AutoFit
            Application.CutCopyMode = False
            On Error Resume Next
            .DrawingObjects.Visible = True
            .DrawingObjects.Delete
            On Error GoTo 0
        End With
    
        'Publish the sheet to a htm file
        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
    
        'Read all data from the htm file into RangetoHTML
        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=")
    
        'Close TempWB
        TempWB.Close savechanges:=False
    
        'Delete the htm file we used in this function
        Kill TempFile
    
        Set ts = Nothing
        Set fso = Nothing
        Set TempWB = Nothing
    End Function
    Function GetBoiler(ByVal sFile As String) As String
    '**** Kusleika
        Dim fso As Object
        Dim ts As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
        GetBoiler = ts.readall
        ts.Close
    End Function
    Thanks - Naveed
    -----------------------------
    If the suggestion helps you, then Click * to Add Reputation
    To Attach File: Go Advanced>>Manage Attachments>>Add Files (In Top Right Corner)>>SelectFiles>>.........Locate Your File(s)>>Upload Files>>Done (In Bottom Right)
    1. Use [code] code tags [\code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  9. #9
    Forum Contributor
    Join Date
    11-19-2015
    Location
    India
    MS-Off Ver
    excel 2013
    Posts
    124

    Re: Default signature at the end of email

    Naveed, that is exactly what I am looking for. Works a treat. Thank you!

    Regards,

    Xlhelp7

  10. #10
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Default signature at the end of email

    Hi Try this below code

    Sub email()
    Dim mainWB As Workbook
    Dim SendID
    Dim CCID
    Dim Subject
    Dim Body
    Dim rng1 As Range
     
    Set otlApp = CreateObject("Outlook.Application")
    Set olMail = otlApp.CreateItem(olMailItem)
    Set Doc = olMail.GetInspector.WordEditor
    Set mainWB = ActiveWorkbook
    SendID = mainWB.Sheets("Product Report").Range("I20").Value
    CCID = mainWB.Sheets("Product Report").Range("I21").Value
    Subject = mainWB.Sheets("Product Report").Range("I22").Value
    Body = mainWB.Sheets("Screenshot").Range("A1:Z500").Value
    '======================================
    snm = "NAVEED" 'signature name which u have given in outlook
    SigString = Environ("appdata") & _
                    "\Microsoft\Signatures\" & snm & ".htm"
    If Dir(SigString) <> "" Then
        Signature = GetBoiler(SigString)
    Else
        Signature = ""
    End If
    
    '===================================
    With olMail
        .To = SendID
        If CCID <> "" Then
          .CC = CCID
        End If
        .Subject = Subject
        mainWB.Sheets("Screenshot").Range("A1:Z500").Copy
        
        Set WrdRng = Doc.Range
    
        .Display
        WrdRng.Paste
    .htmlbody = Signature
        .Display
    End With
    Sheets("Product Report").Select
    
    End Sub
    Function GetBoiler(ByVal sFile As String) As String
    '**** Kusleika
        Dim fso As Object
        Dim ts As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
        GetBoiler = ts.readall
        ts.Close
    End Function
    Last edited by Naveed Raza; 07-19-2016 at 07:30 AM.

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Default signature at the end of email

    Try recording a macro to just send some dummy email and see if the sig gets left off when you run the test macro?

  12. #12
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Default signature at the end of email

    Hi xlhelp7,

    Glad to help you

    if you happy with the solution then could you please close the thread and click on * Add Reputation to say thank.

+ 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. [SOLVED] outlook VBA: how to add alternative signature to email instead of the default
    By Marijke in forum Outlook Formatting & Functions
    Replies: 13
    Last Post: 11-03-2017, 08:36 AM
  2. Use VBA to send email from Outlook and use senders default signature
    By BillDoor in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-21-2015, 11:02 AM
  3. Trying to add a default signature into an email from VBA
    By murp5972 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-13-2015, 09:33 AM
  4. [SOLVED] default email signature
    By bigfishprf in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-08-2015, 10:55 AM
  5. generating automatic email with default signature and hyperlink
    By jerrydiaz in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 04-24-2014, 11:55 AM
  6. send selected range in email with default outlook email signature included
    By mdsickler in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-04-2013, 10:50 PM
  7. Unable to link default email signature to email
    By paxile2k in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2010, 06:52 PM

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