Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Location: India
Posts: 24
Send a message via Skype™ to Gaura215
Default Mailing each worksheet in Workbook

Hello

I have 70-80 worksheets in my workbook, which I need to send to different receipients as an individual workbooks. My codes looks like below:

Sub Mail_Every_Worksheet()
'Working in 2000-2010
Dim sh As Worksheet
Dim wb As Workbook
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
TempFilePath = Environ$("temp") & "\"
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2010
FileExtStr = ".xlsm": FileFormatNum = 52
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set OutApp = CreateObject("Outlook.Application")
For Each sh In ThisWorkbook.Worksheets
If sh.Range("AA65536").Value Like "?*@?*.?*" Then
sh.Copy
Set wb = ActiveWorkbook
TempFileName = "Agent:" & sh.Name & " (" & "107" & ") " & "CEVA USA REPORTS FOR " & Format(Now, "mmm-yy")
Set OutMail = OutApp.CreateItem(0)
With wb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.to = sh.Range("AA65536").Value
.CC = ""
.BCC = ""
.Subject = "Testing Automation Script"
.Body = "Hi" _
& "The Following PS 107 Report." _
& "The following are reports for the month of " & Format(Now, "mmm-yy") _
& "I am in charge of the distribution of the PS reports;" _
& "should you have any questions/comments regarding the entries in these reports, please" _
& "contact the station in charge of the shipment in question."
.Attachments.Add wb.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Send
End With
On Error GoTo 0
.Close savechanges:=False
End With
Set OutMail = Nothing
Kill TempFilePath & TempFileName & FileExtStr
End If
Next sh
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub

I have two doubts in this:

Firstly, I am facing the debug error in ".SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum". I am confused why is so.
Secondly, I want the body of the mail like Hi in first line then second line should be like "The Following PS 107 Report." & "The following are reports for the month of " & Format(Now, "mmm-yy") and then leaving the next line blank, it should start a new paragraph as "I am in charge of the distribution of the PS reports; should you have any questions/comments regarding the entries in these reports, please contact the station in charge of the shipment in question."

Please someone help.
__________________
Regards
Gaurav
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
E-mailing a worksheet big_wilkie Excel Discussion (Misc queries) 1 October 9th 09 05:30 AM
e-mail individual worksheet/tab w/out e-mailing entire workbook? Cookie Monster Excel Discussion (Misc queries) 1 March 13th 09 10:26 PM
E-mailing a worksheet from a workbook using Windows Mail sparks41 New Users to Excel 2 December 30th 08 11:00 PM
mailing one sheet from workbook nospaminlich Excel Discussion (Misc queries) 2 June 30th 05 12:36 AM
Worksheet e-mailing Always Frustrated Excel Worksheet Functions 1 June 22nd 05 10:52 PM


All times are GMT +1. The time now is 10:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"