Jyggalag

Active Member
Joined
Mar 8, 2021
Messages
422
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all,

I have this code attached to a macro:

VBA Code:
Option Explicit

Private Const FilePath As String = "R:\LXI_DLL\ZGJ_COMMON\FLD COMP FOLDER\12-FOLDER\TOPIC 2\ATTACHMENTS\"
Sub send_email_complete()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim i As Long
    Dim ws As Worksheet
    Dim col As New Collection, itm As Variant
    Dim ToAddress As String, CCAddress As String, EmailSubject As String
   
    '~~> Change this to the relevant worksheet
    '~~> that has the emails (right now Search Export has it)
    Set ws = ThisWorkbook.Sheets("Search Export")

    Set OutApp = CreateObject("Outlook.Application")
    
    Dim BodyText As String
    BodyText = ws.Range("G2") & "<BR>" & "<BR>" & _
         ws.Range("G4") & "<BR>" & _
         ws.Range("G5") & "<BR>" & _
         ws.Range("G6") & "<BR>" & "<BR>" & _
         ws.Range("G8") & "<BR>" & "<BR>" & _
         ws.Range("G10") & "<BR>" & "<BR>" & _
         "<b>" & ws.Range("G12") & "</b><br>" & "<BR>" & _
         ws.Range("G14") & "<BR>" & _
         ws.Range("G15")
   Dim AttachmentName As String
   AttachmentName = FilePath & ws.Cells(2, 6).Value2
         
    For i = 2 To ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
      '~~> Constructing addresses and subject
      
      ToAddress = ws.Cells(i, 2).Value2 & ";" & ws.Cells(i, 3).Value2 & ";" & ws.Cells(i, 4).Value2
                  
      CCAddress = ws.Cells(i, 5).Value2
                   
      EmailSubject = ws.Cells(i, 1).Value2
      '~~> This creates a new email (so we can send out multiple emails)
      Set OutMail = OutApp.CreateItem(0)

      With OutMail
         .To = ToAddress
         .CC = CCAddress
         .Subject = EmailSubject
         .HTMLBody = BodyText
         .Attachments.Add AttachmentName
         
         .Send
      
      End With
   Next i

End Sub

The macro used to work, but when I use it down it rebugs and highlights this:

1648024450437.png


This is the file by the way:

1648024523201.png


So the attachment cell is located in cell F2
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This is the highlight btw:

1648024630510.png


However, my file path is correct (i also ended it with a reverse backslash) and the file name is correct and it is an excel .XLSX file
 
Upvote 0
UPDATE! Fixed it! My attachment had a space in the name too much lol.

Sorry guys
 
Upvote 0
Solution

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top