0
votes

I have a macro that begins with an Excel sheet, and will be sent through Outlook email to colleagues.

I've been trying to use the Ron de Bruin link to add a saved Signature to an Outlook email, but it's saying "File Not Found". https://www.rondebruin.nl/win/s1/outlook/signature.htm

-The Signature is not set as Default, because I have more than one Signature saved.

-The Path matches what it should be when I perform a Debug.Print

C:\Users\cday\AppData\Roaming\Microsoft\Signatures\Inventory Report.htm

Sub Setup_Email()
    
    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem
    
    Set OutApp = CreateObject("Outlook.application")
    Set OutMail = OutApp.CreateItem(olMailItem)
        
    Dim StrSignature As String
    Dim SPath As String
    
    SPath = Environ("appdata") & "\Microsoft\Signatures\Inventory Report.htm"
    Debug.Print SPath
    
    StrSignature = Getsignature(SPath)
    
    With OutMail
        .Display
        .to = "People"
        .CC = "More People"
        .Subject = ThisWorkbook.Name
        .Attachments.Add ActiveWorkbook.FullName
        .HTMLBody = StrSignature
    End With
        
    On Error GoTo 0
        
    Set OutMail = Nothing
    Set OutApp = Nothing
    
End Sub
    
Function Getsignature(ByVal sFile As String) As String
    
    Dim fso As Object
    Dim ts As Object
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2) **"File Not Found"**
    
    Getsignature = ts.readall
    
    ts.Close
    
End Function
2

2 Answers

0
votes

Do you actually see the signature file with that name in Windows Explorer? Keep in mind that "Signatures" folder name is localized. The actual folder name is stored in the Signatures value at

HKEY_CURRENT_USER\Software\Microsoft\Office\<version>\Common\General
0
votes

I relooked at my macro as was missing the Call - GetBroiler Function: Sub Setup_Email()

Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim SigString As String
Dim Signature As String

Set OutApp = CreateObject("Outlook.application")
Set OutMail = OutApp.CreateItem(olMailItem)

SigString = Environ("appdata") & "\Microsoft\Signatures\Inventory Report.htm"

If Dir(SigString) <> "" Then
    Signature = GetBoiler(SigString)
Else
    Signature = ""
End If

On Error Resume Next

With OutMail
    .Display
    .to = "People"
    .CC = "More People"
    .Subject = ThisWorkbook.Name
    .Attachments.Add ActiveWorkbook.FullName
    .HTMLBody = Signature
End With


Set OutMail = Nothing
Set OutApp = Nothing

End Sub

Function GetBoiler(ByVal sFile As String) As String 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