Hi,
May i know what went wrong with my code?I want to attach file with name "ITST01" in the folder which is defined by DialogFolderPicker.But there is error return stated cannot find the file, please ensure the path is correct.
Sub SendEmail()
Dim Fpath As String
Dim diaFolder As FileDialog
Dim strfolder As String
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Show
strfolder = diaFolder.SelectedItems(1)
'Mth = InputBox("Please insert Month, MMYY")
'DueDate = InputBox("Please insert due date")
Call Test
End Sub
Sub Test()
Dim EmailSubject As String
Dim SendTo As String
Dim EmailBody As String
Dim ccTo As String
Dim strpath As String
EmailSubject = "HC allocation_Test Engineer" & "_" & Mth
strpath = Dir(strfolder & "1TST01.xlsx")
SendTo = "name@yahoo.com" ' Use name of distribution list
EmailBody = "Hi," & vbCrLf & vbCrLf & "Kindly review HC allocation file and update the allocation % if there is any changes" & vbCrLf & vbCrLf & "Due Date: " & DueDate & vbCrLf & vbCrLf & "Rgds, SK"
Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
.Subject = EmailSubject
.To = SendTo
.Body = EmailBody
.Attachments.Add (strpath)
.Display
End With
Set App = Nothing
Set Itm = Nothing
End Sub
May i know what went wrong with my code?I want to attach file with name "ITST01" in the folder which is defined by DialogFolderPicker.But there is error return stated cannot find the file, please ensure the path is correct.
Code:
Dim Fpath As String
Dim diaFolder As FileDialog
Dim strfolder As String
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Show
strfolder = diaFolder.SelectedItems(1)
'Mth = InputBox("Please insert Month, MMYY")
'DueDate = InputBox("Please insert due date")
Call Test
End Sub
Sub Test()
Dim EmailSubject As String
Dim SendTo As String
Dim EmailBody As String
Dim ccTo As String
Dim strpath As String
EmailSubject = "HC allocation_Test Engineer" & "_" & Mth
strpath = Dir(strfolder & "1TST01.xlsx")
SendTo = "name@yahoo.com" ' Use name of distribution list
EmailBody = "Hi," & vbCrLf & vbCrLf & "Kindly review HC allocation file and update the allocation % if there is any changes" & vbCrLf & vbCrLf & "Due Date: " & DueDate & vbCrLf & vbCrLf & "Rgds, SK"
Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
.Subject = EmailSubject
.To = SendTo
.Body = EmailBody
.Attachments.Add (strpath)
.Display
End With
Set App = Nothing
Set Itm = Nothing
End Sub
Code: