I downloaded your "Auto-Invoice email with button click" from your site. I massaged it to conform to my appliocation.
The problem is that it hanges up on "..Attachment.Add newFilename", if Outlook is not already open and has oppened at least one existing email. (Strange). If I go ahead and open Outlook, open and existing email, it runs fine. What the heck is going on? If I go to debug and put the cursor on the highlighted error, it will show the complete file name. {newFilename = "2023-08-10 - IBEW Retired Members Club 479 Tally Sheet.PDF"} Like I said, it runs great if Outlook is already open. If Outlook is not open, I get this message when i run the macro.
Run-time error '-2147024894 (800700002)' Cannot find this file. Verify the path and the file name are correct.
Option Explicit
Sub Email_Tally()
' https://www.teachexcel.com/
'' Full VBA/Macro Course: https://www.teachexcel.com/vba-course-update.php?src=tut_file
'
' Email PDF
' Variables
Dim outlookApp As Object
Dim emailItem As Object
Dim emailSubject As String
Dim newFilename As String
Dim emailBody As String
Dim MyPath As String
' Get a reference to the Outlook Application Object.
Set outlookApp = CreateObject("Outlook.Application")
Set emailItem = outlookApp.CreateItem(0)
' Make a filename.
newFilename = Cells(15, "F").Text & " - " & Cells(16, "D").Value & ".PDF"
' Make the PDF.
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=newFilename, _
Quality:=xlQualityStandard, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
' Email Section
' Setup values for the email.
emailSubject = "IBEW Retired Members Club #479 Tally Sheet"
emailBody = "Attached is the IBEW Retired Members Club #479 Tally Sheet" & vbNewLine
' Build the Email
With emailItem
.To = Worksheets("Tally Sheet").Range("Tally_Email").Value
.Bcc = Worksheets("Tally Sheet").Range("BlindCopyEmail").Value
.Subject = emailSubject
.Body = emailBody
.Attachments.Add newFilename
.Display ' or .Send
End With
Range("K12").Select
MsgBox "OK, the Tally Sheet email is sent! "
End Sub