how to add my signature with images to macro

atditiljazi

New Member
Joined
Nov 22, 2022
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Hello everyone, please find my macro below. Is there a method for including my Outlook signature that holds images? I am struggling to figure it out for myself.

i will be grateful for your help

VBA Code:
Sub send_email()

Dim rng As Range, c As Range, AddrRange As Range
Dim i As Long, lastRow As Long, lastRow2 As Long
Dim targetWorkbook As Workbook
Dim objFSO As Object
Dim varTempFolder As Variant, v As Variant
Dim AttFile As String, Dest As String, myCC As String
Dim sh As Worksheet, shMail As Worksheet

Set sh = Sheets("order book")
Set shMail = Sheets("Sheet2")

lastRow = sh.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lastRow2 = shMail.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set AddrRange = shMail.Range("A1:a" & lastRow2)

v = sh.Range("A2:v" & lastRow).Value

Set objFSO = CreateObject("Scripting.FileSystemObject")
varTempFolder = objFSO.GetSpecialFolder(2).Path & "\Temp " & Format(Now, "dd-mm-yyyy- hh-mm-ss")
objFSO.CreateFolder (varTempFolder)

Application.ScreenUpdating = False

With CreateObject("scripting.dictionary")

For i = 2 To UBound(v)
    If Not .exists(v(i, 2)) Then
        .Add v(i, 2), Nothing

        With sh
            .Range("A1").AutoFilter 2, v(i, 2)
            Set rng = .AutoFilter.Range
           Set targetWorkbook = Workbooks.Add
            .UsedRange.SpecialCells(xlCellTypeVisible).Copy
        End With
         
         With targetWorkbook.Worksheets(Sheets.Count)
            .Range("A1").PasteSpecial xlPasteColumnWidths
            .Range("A1").PasteSpecial xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            .Range("A1").PasteSpecial xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        End With
                    
        AttFile = v(i, 2) & ".xlsx"
    
        On Error Resume Next
        r = 0
        r = Application.WorksheetFunction.Match(v(i, 2), AddrRange, 0)
        On Error GoTo 0
        
        If r > 0 Then
            With shMail
                Dest = .Range("B" & r)
                myCC = .Range("C" & r)
            End With
        
        
            With targetWorkbook
                '.ActiveSheet.Columns.AutoFit
                .SaveAs varTempFolder & "" & AttFile
                .Close
            End With
        
            With CreateObject("Outlook.Application").CreateItem(0)
    .To = Dest
    .CC = myCC
    .Subject = "order book"
    .Body = "Please find an open order book attached.In column L, please enter the expected delivery date. In column M, please enter the confirmed quantity.Please confirm the unit cost in column N.Please enter any comments in Column O, for example, if an order is delayed, please enter the reason why.If an order is Free Issue, please disregard the cost column. Please return the spreadsheet as soon as possible so that I can update my system accordingly. Kind Regards. Ardit Iljazi "
    
    ' Add sentence breaks
    .Body = Replace(.Body, ".", "." & vbCrLf)
    
    .Attachments.Add varTempFolder & "" & AttFile
    '.display 'to show
    .Send 'to send
End With

        Else
            MsgBox v(i, 2) & " not found.", vbExclamation
            Exit For
        End If
    End If
Next i
End With

Range("A1").AutoFilter
Application.ScreenUpdating = True

objFSO.deletefolder (varTempFolder)
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
If you have it set up so that your signature is automatically added to any newly created email, try the following...

VBA Code:
With CreateObject("Outlook.Application").CreateItem(0)
    .To = Dest
    .CC = myCC
    .Subject = "order book"
   
    ' Get the existing signature from the email
    Dim signature As String
    signature = .htmlbody
   
    .Body = "Please find an open order book attached.In column L, please enter the expected delivery date. In column M, please enter the confirmed quantity.Please confirm the unit cost in column N.Please enter any comments in Column O, for example, if an order is delayed, please enter the reason why.If an order is Free Issue, please disregard the cost column. Please return the spreadsheet as soon as possible so that I can update my system accordingly. Kind Regards. Ardit Iljazi "
   
    ' Add sentence breaks
    .Body = Replace(.Body, ".", "." & vbCrLf)
   
    .htmlbody = .htmlbody & signature
   
    .Attachments.Add varTempFolder & "" & AttFile
    .display 'to show
    '.Send 'to send
End With

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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