Forum

Run-Time Error 53 F...
 
Notifications
Clear all

Run-Time Error 53 File not found

6 Posts
2 Users
0 Reactions
158 Views
(@kwesmc1)
Posts: 31
Trusted Member
Topic starter
 

Hello everyone,

I am getting a Run-Time Error 53 File not found when I call my function on this line of code:
Set TSet = fso.GetFile(fPath).OpenAsTextStream(1, -2)

Can anyone please help?
Thank you,
Ken Mc

Function GetSignature(fPath As String) As String
    Dim fso As Object
    Dim TSet As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set TSet = fso.GetFile(fPath).OpenAsTextStream(1, -2)
    GetSignature = TSet.readall
    TSet.Close
End Function

Sub Outlook_Default_Signature_With_Image()

    'Do not forget to change the email ID
    'before running this code
    Dim OlApp As Object
    Dim NewMail As Object
    Dim EmailBody As String
    Dim StrSignature As String
    Dim sPath As String
    Dim signImageFolderName As String
    Dim completeFolderPath As String

    Set OlApp = CreateObject("Outlook.Application")
    Set NewMail = OlApp.CreateItem(0)
sPath = Environ("appdata") & "MicrosoftSignaturesDefault.htm"
    ' Here Since we are talking about
    ' the HTML email then we need to
    ' write the Body of the Email in
    ' HTML.
    EmailBody = "Hello Friends !!" & ""
   
    sPath = Environ("appdata") & "MicrosoftSignaturesDefault.htm"
   
    StrSignature = GetSignature(sPath)
completeFolderPath = Environ("appdata") & "MicrosoftSignatures" & signImageFolderName

    On Error Resume Next
    With NewMail
        .To = "[email protected]"
       ' .CC = "anybody.com"
       ' .BCC = "anybodyelse.com"
        .Subject = "Hello"
        ' Important! Before writing the body of your email
        ' you should display the mail
       
        .display
        ' Here at the end of the Email Body
        ' HTML Signature is inserted.
        .htmlBody = EmailBody & StrSignature
        .send
    End With
    On Error GoTo 0
    Set NeMail = Nothing
    Set OlApp = Nothing
End Sub

 
Posted : 03/04/2018 8:56 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Kenneth,

Testing this code I also get an error at the same point because the file C:UserspgtAppDataRoamingMicrosoftSignaturesDefault.htm does not exist.

I assume you have triple checked that this file exists on your PC?

When I change the htm sig filename to something that does exist, the error does not occur.

Regards

Phil

 
Posted : 04/04/2018 1:42 am
(@kwesmc1)
Posts: 31
Trusted Member
Topic starter
 

Thank you very much Phil!
I will give that a try and let you know.
Thanks again,

Ken Mc

 
Posted : 04/04/2018 12:21 pm
(@kwesmc1)
Posts: 31
Trusted Member
Topic starter
 

After-display.jpgAfter-Preview.jpgPhil,
That worked for me too, but when stepping through code and get to .display, email shows me my image signature and then when the code gets to
.htmlBody = EmailBody & StrSignature and .preview, I get this: See attached.
Would you know why this is happening?

Thanks!

 
Posted : 04/04/2018 5:14 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Ken,

It would appear that when you read the sig file in, and then add it as part of the HTML body of the email, Outlook is messing up the links to the location of images in the original sig.

Outlook is probably creating a temp file somewhere to hold the HTML contents of your new email, but isn't copying/referencing the images correctly - hence the broken image.

I found that when the image in the sig is stored locally, the image breaks.  If you edit your sig and insert an image that is stored out there on the 'net somewhere, Outlook loads that image correctly.

So you'll need to copy your image onto a web server somewhere, then edit the image link in your sig to point to that.

Cheers

Phil

 
Posted : 05/04/2018 2:13 am
(@kwesmc1)
Posts: 31
Trusted Member
Topic starter
 

Thanks Phil.
Looks like more hassle than I want to go through. I suppose I will just go back to a text sig file.

Regards,

Ken Mc

 
Posted : 05/04/2018 11:57 am
Share: