I am sending email using vb code. My code is working fine.
I have one difficulty...
Code:Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
fileName = List1.Text ' here i am setting the filename as selected worksheet from list.
Debug.Print fileName
SaveName = folderPath & "RightAnswersTempWorkbooks" & Num & "\" & StripChars(fileName, "[/,\\,*,?,"",<,>,|,:]", "") 'folderpath is the path where the original selected workbook is located.num is random number.
ActiveSheet.Copy
Set Wkb = ActiveWorkbook
Wkb.SaveAs SaveName
With EmailItem
.Subject = txtsubject.Text
.Body = txtmessage.Text
.To = Txtname.Text
.Attachments.Add Wkb.FullName ' wkb.fullname is complete path
.send
End With
What i am doing is .. user can select a workbook.All the sheets from that workbook will be listed in a listview.Now user can select a single sheet from listview. i am copying the selected worksheet in a new tempworkbook, and placing this workbook in new folder (folderPath & "RightAnswersTempWorkbooks" & Num) while sending mail i am attaching that temp workbook to mail.After sending the mail i am destroying the folder (folderPath & "RightAnswersTempWorkbooks" & Num)
I want my code to work if user selects more than one worksheet. i.e for each selected worksheet i will copy the sheet into new folder(folderPath & "RightAnswersTempWorkbooks" & Num). and while sending i will attached these files from folders as an attachment.
