Hello,
I am working on a project to save emails to a specific subfolder in the drafts. Everything works perfectly up to me putting them into a specific folder.
The folder would be "Drafts"\BACode
I just need help on inserting that into my code
I am working on a project to save emails to a specific subfolder in the drafts. Everything works perfectly up to me putting them into a specific folder.
The folder would be "Drafts"\BACode
I just need help on inserting that into my code
Code:
Option Explicit
Public Timing As String
Public BACode As Variant
Sub DraftOutlookEmails()
'*******************************************************************
'Microsoft Outlook XX.X Object Library is required to run this code
'*******************************************************************
Dim objOutlook As Outlook.Application
Dim Mail As Outlook.MailItem
Dim lCounter As Long
Set objOutlook = Outlook.Application
Dim wsMLOG As Excel.Worksheet
Set wsMLOG = Sheets("Master Log")
Dim rngTable1 As Excel.Range
Set rngTable1 = wsMLOG.Range("A4").CurrentRegion
Dim rngLessHeader As Excel.Range, rngRows As Long, rngRow1 As Long
Set rngLessHeader = gf_rngGet_TableData_Range(rngTable1)
Dim AdminWeek As Integer
BACode = InputBox("Enter BA Code")
AdminWeek = MsgBox("Admin Week?", vbYesNo)
UserForm1.Show vbModal
rngRows = rngLessHeader.Rows.Count
rngRow1 = rngLessHeader.Rows(1).Count
Dim pathStr As String
pathStr = "Path removed for security"
Dim fileStr As String
Dim fileStr2 As String
Dim mailAddress As String
Sheets("Master Log").Select
Dim i As Long
'
If AdminWeek = vbNo Then
For i = rngRow1 To rngRows
If Cells(i, 5) = BACode Then
If Cells(i, 7) = "E-mail" Then
If Cells(i, 9) = Timing Then
Set Mail = objOutlook.CreateItem(olMailItem)
Mail.To = wsMLOG.Range("L" & i).Value & ";" & wsMLOG.Range("M" & i).Value & ";" & wsMLOG.Range("N" & i).Value & ";" & wsMLOG.Range("O" & i).Value & ";" & wsMLOG.Range("P" & i).Value & ";" & wsMLOG.Range("Q" & i).Value & ";" & wsMLOG.Range("R" & i).Value & ";" & wsMLOG.Range("S" & i).Value & ";" & wsMLOG.Range("T" & i).Value & ";" & wsMLOG.Range("U" & i).Value & ";" & wsMLOG.Range("V" & i).Value & ";" & wsMLOG.Range("W" & i).Value & ";" & wsMLOG.Range("X" & i).Value & ";" & wsMLOG.Range("Y" & i).Value & ";" & wsMLOG.Range("Z" & i).Value & ";" & wsMLOG.Range("AA" & i).Value & ";" & wsMLOG.Range("AB" & i).Value
Mail.Subject = wsMLOG.Range("B" & i).Value & " " & wsMLOG.Range("C" & i).Value
Mail.Body = Sheets("Sheet1").Range("A1").Text
fileStr = wsMLOG.Range("C" & i).Value & ".pdf"
If FileExists(pathStr & BACode & "\" & fileStr) Then
Mail.Attachments.Add pathStr & BACode & "\" & fileStr
Else
Mail.Delete
End If
On Error Resume Next
Mail.Close (olSave)
Set Mail = Nothing
End If
End If
End If
Next
End If
[\Code]