Attachment missing when running mail from VBA
<p>I'm running an invoicing program in Excel 2013/2016. The purpose is to create an invoice, save as PDF, create mail and attach the PDF - Fully automated.</p>

<p>My code is breaking down by the line:</p>

<p><strong>objMessage.AddAttachment = GemFilSom (link to lib and file)</strong></p>

<p>Here's is the code:</p>

<pre><code>Private Sub CommandButton2_Click()

Dim Sender As String
Dim Modtager As String
Dim Emne As String
Dim Tekst As String
Dim Vedhaft As String
Dim Tekst1 As String
Dim Tekst2 As String
Dim Tekst3 As String
Dim Tekst4 As String
Dim Tekst6 As String
Dim Fulltekst As String
Dim Pw As String
Dim Port As String
Dim SMTPUdbyder As String
Dim GemFilSom As String

Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
Const cdoAnonymous = 0
Const cdoBasic = 1
Const cdoNTLM = 2




    Sheets("Udskrift").Activate

'    ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True, _
'        IgnorePrintAreas:=False


GemFilSom = Worksheets("FakturaList").Range("L8").Value 'lib + filename

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=GemFilSom _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False

Afsender = Worksheets("FakturaList").Range("L23").Value   'from
Modtager = Worksheets("FakturaList").Range("L24").Value   'to
Emne = Worksheets("FakturaList").Range("L25").Value         'Subject
Tekst1 = Worksheets("FakturaList").Range("L14").Value       'Bodytekst
Tekst2 = Worksheets("FakturaList").Range("L15").Value       '   "
Tekst3 = Worksheets("FakturaList").Range("L16").Value       '   "
Tekst4 = Worksheets("FakturaList").Range("L17").Value       '   "
Tekst5 = Worksheets("FakturaList").Range("L18").Value       '   "
Tekst6 = Worksheets("FakturaList").Range("L19").Value       '   "
Pw = Worksheets("FakturaList").Range("L22").Value           'Password  
Port = Worksheets("FakturaList").Range("L31").Value         'SMTP Port
SMTPUdbyder = Worksheets("FakturaList").Range("L32").Value  'SMTP Server

Vedhaft = Worksheets("FakturaList").Range("L27").Value      'Attachment 'Lib+Filename

Fulltekst = Tekst1 &amp; vbNewLine &amp; vbNewLine &amp; vbNewLine &amp; vbNewLine &amp; Tekst2 &amp; vbNewLine &amp; Tekst3 &amp; vbNewLine &amp; vbNewLine &amp; Tekst4 &amp; vbNewLine &amp; vbNewLine &amp; Tekst5 &amp; vbNewLine &amp; Tekst6
'Bodytext

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = Emne
objMessage.From = Afsender
objMessage.To = Modtager
objMessage.Bcc = Afsender
**objMessage.AddAttachment = GemFilSom**   ' This line doesn't work and do not 'attach
objMessage.TextBody = Fulltekst


***objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/Attachment") = GemFilSom***        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPUdbyder
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = Afsender
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Pw
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = Port
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10

objMessage.Configuration.Fields.Update

objMessage.Send

End Sub
</code></pre>

<p>I've spent 4 days testing googleing and what so.... Can anyone please help?
I have a <strong>basic</strong> understanding of VBA</p>

<p>Best reagsrd
Michael</p>