PDA

View Full Version : Picture below default siganture



Lef_pl
09-13-2021, 06:02 AM
Hello,

I'm stuck with below problem.

I have a macro that replies to all with attachments. It works like a charm.
I would like to add a picture below my default signature when I reply to all.

I can make it work when it's at the end of entire communication or at the beginning of my reply.
Can You point me in the right direction?

Picture is located on the sharde drive.

This is my partial code responible for placing picture


With xReplyMailItem
.Display
.Subject = "[I] " & Item.Subject
.HTMLBody = strbody & "<br>" & .HTMLBody
.Attachments.Add "W:\ABC\0 Archiwum\picture1", olByValue, 0
.HTMLBody = strbody & "<br></br>" & "<img src=""W:\ABC\0 Archiwum\picture1""width=50>" & .HTMLBody
End With
End With


Picture is placed at the beginning of my reply.

arnelgp
09-13-2021, 06:09 AM
With xReplyMailItem
.Subject = "[I] " & Item.Subject
.Attachments.Add "W:\ABC\0 Archiwum\picture1", olByValue, 0
.HTMLBody = strbody & "<br></br>" & "<img src=""W:\ABC\0 Archiwum\picture1"" width=50>" & .HTMLBody
.Display
End With

Lef_pl
09-13-2021, 06:28 AM
Hello Arnelgp,

Thank You for quick reply.
Unfortunatelly it's still placed above default signature.

[PICTURE]


[MY DEFAULT SIGNATURE]

I'm wondering how can I place this picture below signature?

Im replying to all and when I do .HMTLbody is entire previous communication.

I have no problem with placing the picture under signature when I creat new message.

arnelgp
09-13-2021, 06:03 PM
can you find out what is the name of your default signature
(outlook->options->mail->signatures)
if you have found out, replace mySig on the code with your signature name (do not delete the .htm extension):

also i noticed your picture does not have an extension so i add .png (replace it with the extension you have).



Dim sig As String
sig = ReadSignature("Mysig.htm")
With xReplyMailItem
.Subject = "[I] " & Item.Subject
.Attachments.Add "W:\ABC\0 Archiwum\picture1.png", olByValue, 0
.HTMLBody = strbody & "<br></br>" & "<img src=""W:\ABC\0 Archiwum\picture1.png"" width=50>" & & "<p><br/><br/></p>" & sig
.Display
End With




Public Function ReadSignature(sigName As String) As String
' arnelgp
'
' sigName should include the .htm extension
'
Dim appDataDir As String
Dim sig As String
Dim sigPath As String
Dim fileName As String
appDataDir = Environ$("APPDATA") & "\Microsoft\Signatures"
sigPath = appDataDir & "\" & sigName
With CreateObject("Scripting.FileSystemObject")
sig = .OpenTextFile(sigPath).ReadAll
End With
'With CreateObject("Scripting.FileSystemObject").CreateTextFile(Environ("userprofile") & "\desktop\sig2.txt", True)
' .Write sig
' .Close
'End With


' fix relative references to images, etc. in sig
' by making them absolute paths, OL will find the image
fileName = Replace$(sigName, ".htm", "_files/")
sig = Replace$(sig, fileName, appDataDir & "\" & fileName)
ReadSignature = sig
End Function

gmayor
09-14-2021, 02:10 AM
It would probably be simpler to use the Word message editor e.g as follows. Incidentally using this method, if the image is part of your signature, there would be no need to add it in code.


Sub MyReply()
Dim olMsg As MailItem
Dim olReply As MailItem
Dim olTemp As MailItem
Dim olInsp As Inspector
Dim wdDoc As Object, wdDoc2 As Object
Dim oRng As Object, oMsgRng As Object
Dim oBookmark As Object

Dim strTo As String
Dim strSubject As String

On Error GoTo err_Handler
Set olMsg = ActiveExplorer.Selection.Item(1)
With olMsg
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oMsgRng = wdDoc.Range
End With
Set olTemp = olMsg.Reply
strTo = olTemp.Recipients(1).Address
strSubject = "[I] " & olTemp.Subject

Set olReply = CreateItem(olMailItem)
With olReply
.BodyFormat = olFormatHTML
.Display
.To = strTo
.Subject = strSubject
Set olInsp = .GetInspector
Set wdDoc2 = olInsp.WordEditor
Set oRng = wdDoc2.Range
oRng.collapse 0
oRng.formattedtext = oMsgRng.formattedtext
Set oBookmark = wdDoc2.Bookmarks("_MailAutoSig")
Set oRng = oBookmark.Range
oRng.collapse 0
oRng.InlineShapes.AddPicture FileName:= _
"W:\ABC\0 Archiwum\picture1.jpg"

Set oRng = wdDoc2.Range
oRng.collapse 1
oRng.Select
End With
olTemp.Close olDiscard
lbl_Exit:
Set olTemp = Nothing
Set olMsg = Nothing
Set olReply = Nothing
Set wdDoc = Nothing
Set wdDoc2 = Nothing
Set oRng = Nothing
Set oMsgRng = Nothing
Exit Sub
err_Handler:
Err.Clear
GoTo lbl_Exit
End Sub