I have set of parameters ( if then statements - to exclude certain rows) that I need to add to this code before it makes/saves the attachment. Where would be the best place to set them in the code? I’m absolutely stuck on this.
VBA Code:
Option Explicit
Sub sintek()
Dim Data, Dict As Object, Path As String, File As String, i As Long
Set Dict = CreateObject("Scripting.Dictionary")
Path = ThisWorkbook.Path: Sheets.Add.Name = "Temp"
With Sheets("Sheet1").ListObjects(1).Range
Data = .Value
For i = 2 To UBound(Data, 1)
If Not Dict.exists(Data(i, 4)) Then
File = Path & "\" & Data(i, 4)
Dict.Add Data(i, 4), 1
.AutoFilter 4, Data(i, 4)
.SpecialCells(12).Copy Sheets("Temp").Range("A1")
.AutoFilter
With Sheets("Temp")
.Columns.AutoFit
.Copy
ActiveWorkbook.SaveAs File & ".xlsx", 51
ActiveWorkbook.Close saveChanges:=False
.UsedRange.Delete
End With
With CreateObject("Outlook.Application").CreateItem(0)
.Display
.To = Data(i, 12)
.Subject = "Whatever"
.Body = "Whatever you want to say"
.Attachments.Add File & ".xlsx"
'.Send
.Display
Kill File & ".xlsx"
End With
End If
Next i
End With
Application.DisplayAlerts = False: Sheets("Temp").Delete: Application.DisplayAlerts = True
End Sub
Last edited by a moderator: