J
joox
I have a column of email adresses(B) and a column of files(C) which need
to be attached in the emails. The spreadsheet shows that files in both
C1 and C2 need to go to (e-mail address removed) -- but the script will not send the
email in the second row w/o an email address in there. This doesn't
seem like a problem, but some addresses have about 20 files and I dont
want to send them 20 separate emails... I'm guessing I need to setup an
array to facilitate the various numbers of attachements but I'm new at
this and don't know how!
Any help is appreciated,
MY SPREADSHEET:
Code:
--------------------
A1: B1: (e-mail address removed) C1: C:/file1.exe
A2: B2: C2: C:/file2.exe
A2: B3: (e-mail address removed) C3: C:/file3.exe
--------------------
THE CODE (PARTIAL):
Code:
--------------------
Set varOutApp = CreateObject("Outlook.Application")
Set varSendIt = varOutApp.CreateItem(0)
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
For Each cell In Sheets("Sheet1").Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Offset(0, 1).Value <> "" Then
If cell.Value <> "" And Dir(cell.Offset(0, 1).Value) <> "" Then
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = cell.Value
.Subject = "Testfile"
.Body = "Hi "
.Attachments.Add cell.Offset(0, 1).Value
.Send 'Or use Display
End With
Set OutMail = Nothing
End If
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
to be attached in the emails. The spreadsheet shows that files in both
C1 and C2 need to go to (e-mail address removed) -- but the script will not send the
email in the second row w/o an email address in there. This doesn't
seem like a problem, but some addresses have about 20 files and I dont
want to send them 20 separate emails... I'm guessing I need to setup an
array to facilitate the various numbers of attachements but I'm new at
this and don't know how!
Any help is appreciated,
MY SPREADSHEET:
Code:
--------------------
A1: B1: (e-mail address removed) C1: C:/file1.exe
A2: B2: C2: C:/file2.exe
A2: B3: (e-mail address removed) C3: C:/file3.exe
--------------------
THE CODE (PARTIAL):
Code:
--------------------
Set varOutApp = CreateObject("Outlook.Application")
Set varSendIt = varOutApp.CreateItem(0)
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
For Each cell In Sheets("Sheet1").Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Offset(0, 1).Value <> "" Then
If cell.Value <> "" And Dir(cell.Offset(0, 1).Value) <> "" Then
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = cell.Value
.Subject = "Testfile"
.Body = "Hi "
.Attachments.Add cell.Offset(0, 1).Value
.Send 'Or use Display
End With
Set OutMail = Nothing
End If
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub