Solved Placement of attachment on Outlook email (1 Viewer)

mib1019

Member
Local time
Yesterday, 19:45
Joined
Jun 19, 2020
Messages
88
Hi all,

I have the following VBA code working correctly, except for the wierd placement of the attached pdf in the body of the email.

Here is the pertinent code.
Code:
'Build email variables
strTo = Me.txtSContactEmail
Debug.Print "Email to " & strTo
strTo = Left(strTo, InStr(strTo, "#mailto") - 1)

Debug.Print "Email to " & strTo

'Get cc info
Dim BContactEmail
BContactEmail = Me.txtBContactEmail
BContactEmail = Left(BContactEmail, InStr(BContactEmail, "#mailto") - 1)
Debug.Print BContactEmail

'if TTT is Ad Buyer, add tim to cc list
Dim AddCC
If BCompanyID = 463 Then
    AddCC = "tim@#####tionteam.com"
Else
    AddCC = ""
End If


strCC = "##keting.com; " & BContactEmail & "; " & AddCC

strSubject = Me.txtFileName

strBody = Me.txtFirstName & ", attached is the "
If CkforRevision = True Then
    strBody = strBody & "REVISED "
End If

strBody = strBody & "Insertion Order for " & txtPeriod & "." & vbNewLine & vbNewLine & _
"Please review, sign and return. " & vbNewLine & vbNewLine & _
"Thanks," & vbNewLine & vbNewLine & _
"Mark"

If oOutlook Is Nothing Then
   Set oOutlook = New Outlook.Application
End If

'Set up message
Set oEmailITem = oOutlook.CreateItem(olMailItem)
With oEmailITem
   .Attachments.Add strFilePath
   .To = strTo
   .CC = strCC
   .Subject = strSubject
   .Body = strBody
   .Display
End With

Here is a picture of the outgoing email. The attachment sits in between the closing and the sender's signature.

Any ideas on how to get it to be situated at the top of the message body?

Thanks for the advice!
MIB
 
Last edited:

mib1019

Member
Local time
Yesterday, 19:45
Joined
Jun 19, 2020
Messages
88
Asked too soon. I sent it to myself and it appears correctly. It still looks funny in the sent items folder though.
 

Isaac

Lifelong Learner
Local time
Yesterday, 18:45
Joined
Mar 14, 2017
Messages
8,777
I used to have people ask me about this. They would ask me why sometimes when Attaching files in Outlook, the attachment "appeared" embedded in some specific place within the text, and other times appeared in the Attachments bar.

I looked into it extensively and concluded two things. First, there is no rhyme or reason why or how you can affect one vs. the other. Second - and more importantly - it's just an appearance, it's not reality. Sometimes I'd send things to people where my sent item showed the attachment within a specific block of text, but they didn't see it that way - and vice versa.

I concluded the whole thing is just an illusion, and a somewhat unpredictable one at that. Just one man's opinion. :)
 

mib1019

Member
Local time
Yesterday, 19:45
Joined
Jun 19, 2020
Messages
88
Thanks, Isaac. You are correct; it shows correctly at the top of the email when I receive it, so I guess I'm good on that.

One other question, though, and that's why is Outlook ignoring my Signature block when sending these attachments via Access VBA? Is there something I need to add in the code to get it to plop my standard signature on the bottom?

MIB
 

Isaac

Lifelong Learner
Local time
Yesterday, 18:45
Joined
Mar 14, 2017
Messages
8,777
I believe your default signature for New messages ought to appear once you execute the Display line. I can't remember right now if there was something else involved to make this happen (for me, it just works). Maybe someone else will chime in on this
 

isladogs

MVP / VIP
Local time
Today, 02:45
Joined
Jan 14, 2017
Messages
18,209
If those are real email addresses in post #1, you should modify them as a matter of security
 

isladogs

MVP / VIP
Local time
Today, 02:45
Joined
Jan 14, 2017
Messages
18,209
Unfortunately, they will be shown in the notification emails of anyone subscribed to this thread. Anyway, they're gone now!
 

Isaac

Lifelong Learner
Local time
Yesterday, 18:45
Joined
Mar 14, 2017
Messages
8,777
You are right. I thought about it after the fact. YIKES!
don't feel bad I've done this before - sometimes even after carefully redacting multiple things and still missing something!
 

mib1019

Member
Local time
Yesterday, 19:45
Joined
Jun 19, 2020
Messages
88
Glad I could edit the original post and take those off!

I have made progress in the Signature block issue by modifying the code:
Code:
'Set up message
Set oEmailITem = oOutlook.CreateItem(olMailItem)

With oEmailITem
    .Display
    signature = oEmailITem.Body
    .Attachments.Add strFilePath
    .To = strTo
    .CC = strCC
    .Subject = strSubject
    .Body = strBody & vbNewLine & signature
    
End With

Any clue why Outlook doesn't add the block formatted as set in the application's options?
 

mib1019

Member
Local time
Yesterday, 19:45
Joined
Jun 19, 2020
Messages
88
I figured it out. Needed .bodyFormat=olFormatHTML in the setup.
 

Isaac

Lifelong Learner
Local time
Yesterday, 18:45
Joined
Mar 14, 2017
Messages
8,777
Awesome! Great job. I thought I remembered something but couldn't for the life of me remember what it was, glad for this thread, now I won't forget :p
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:45
Joined
Sep 21, 2011
Messages
14,238
Awesome! Great job. I thought I remembered something but couldn't for the life of me remember what it was, glad for this thread, now I won't forget :p
Yeah I thought that when I asked about bang ! and dot . 2 years back, and I recently asked the same question 2 years later. :(
 

Users who are viewing this thread

Top Bottom