Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default Emailing A single worksheet wit a email address

Hello from Steved

I got the below by going through Google.

The objective is to email a single Worksheet.

I'm getting a error

Invalid procedure call or argument.

Please help Thankyou.

Sub eMailActiveWorksheet()

Dim OL As Object ' Outlook instantiation
Dim EmailItem As Object ' A new mail item (e-mail)
Dim FileName As String ' The name of the file we are
attaching
Dim lngLoop As Long ' counter for the FileName length
Dim TempChar As String ' used for the loop to test for
unusable characters
Dim SaveName As String ' Attachment's new name, after
cleaning

Application.ScreenUpdating = False ' speed up Excel
processing time
Set OL = CreateObject("Outlook.Application") ' New
Outlook application
Set EmailItem = OL.CreateItem(olMailItem) ' new
MailItem
FileName = ActiveSheet.Name & "1-City" &
ActiveWorkbook.Name ' create a filename on the fly
For lngLoop = 1 To Len(1 - City) ' error check for
unusable chars in the filename
TempChar = Mid(1 - City, y, 1)
Select Case TempChar
Case Is = "/", "\", "*", "?", """", "<", "", "/"
Case Else
SaveName = SaveName & TempChar
End Select
Next lngLoop
ActiveSheet.Cells.Copy ' copy the contents of the
ActiveSheet
Workbooks.Add ' create a new workbook
Selection.PasteSpecial Paste:=xlValues ' paste the
worksheet values into the new book
Selection.PasteSpecial Paste:=xlFormats ' and their
formats
ActiveWorkbook.SaveAs "C:\Temp" & SaveName ' temp file
attachment location
ActiveWorkbook.ChangeFileAccess xlReadOnly ' make
access read only
With EmailItem ' with the newly created e-mail
.Subject = ActiveWorkbook.Name
.Body = "This is an example of a single worksheet
sent by VBa mail"
.To = "1-Depot"
.Importance = olImportanceNormal 'Or
olImportanceHigh Or olImportanceLow
.Attachments.Add "C:\Temp" & SaveName
.Send ' send the worksheet
End With
Kill "C:\Temp" & SaveName ' delete the temporary
attachment
ActiveWorkbook.Close False ' close down the workbook
without saving (single sheet)

Application.ScreenUpdating = True ' always remember to
switch it back on!!

Set OL = Nothing ' clean down memory
Set EmailItem = Nothing

End Sub

..


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Emailing A single worksheet wit a email address

Hi Steved

Look for example code on my site
http://www.rondebruin.nl/sendmail.htm

--
Regards Ron de Bruin
http://www.rondebruin.nl



"Steved" wrote in message ...
Hello from Steved

I got the below by going through Google.

The objective is to email a single Worksheet.

I'm getting a error

Invalid procedure call or argument.

Please help Thankyou.

Sub eMailActiveWorksheet()

Dim OL As Object ' Outlook instantiation
Dim EmailItem As Object ' A new mail item (e-mail)
Dim FileName As String ' The name of the file we are
attaching
Dim lngLoop As Long ' counter for the FileName length
Dim TempChar As String ' used for the loop to test for
unusable characters
Dim SaveName As String ' Attachment's new name, after
cleaning

Application.ScreenUpdating = False ' speed up Excel
processing time
Set OL = CreateObject("Outlook.Application") ' New
Outlook application
Set EmailItem = OL.CreateItem(olMailItem) ' new
MailItem
FileName = ActiveSheet.Name & "1-City" &
ActiveWorkbook.Name ' create a filename on the fly
For lngLoop = 1 To Len(1 - City) ' error check for
unusable chars in the filename
TempChar = Mid(1 - City, y, 1)
Select Case TempChar
Case Is = "/", "\", "*", "?", """", "<", "", "/"
Case Else
SaveName = SaveName & TempChar
End Select
Next lngLoop
ActiveSheet.Cells.Copy ' copy the contents of the
ActiveSheet
Workbooks.Add ' create a new workbook
Selection.PasteSpecial Paste:=xlValues ' paste the
worksheet values into the new book
Selection.PasteSpecial Paste:=xlFormats ' and their
formats
ActiveWorkbook.SaveAs "C:\Temp" & SaveName ' temp file
attachment location
ActiveWorkbook.ChangeFileAccess xlReadOnly ' make
access read only
With EmailItem ' with the newly created e-mail
.Subject = ActiveWorkbook.Name
.Body = "This is an example of a single worksheet
sent by VBa mail"
.To = "1-Depot"
.Importance = olImportanceNormal 'Or
olImportanceHigh Or olImportanceLow
.Attachments.Add "C:\Temp" & SaveName
.Send ' send the worksheet
End With
Kill "C:\Temp" & SaveName ' delete the temporary
attachment
ActiveWorkbook.Close False ' close down the workbook
without saving (single sheet)

Application.ScreenUpdating = True ' always remember to
switch it back on!!

Set OL = Nothing ' clean down memory
Set EmailItem = Nothing

End Sub

.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default Emailing A single worksheet wit a email address

Thankyou Ron.

-----Original Message-----
Hi Steved

Look for example code on my site
http://www.rondebruin.nl/sendmail.htm

--
Regards Ron de Bruin
http://www.rondebruin.nl



"Steved" wrote in

message ...
Hello from Steved

I got the below by going through Google.

The objective is to email a single Worksheet.

I'm getting a error

Invalid procedure call or argument.

Please help Thankyou.

Sub eMailActiveWorksheet()

Dim OL As Object ' Outlook instantiation
Dim EmailItem As Object ' A new mail item (e-mail)
Dim FileName As String ' The name of the file we are
attaching
Dim lngLoop As Long ' counter for the FileName length
Dim TempChar As String ' used for the loop to test

for
unusable characters
Dim SaveName As String ' Attachment's new name, after
cleaning

Application.ScreenUpdating = False ' speed up Excel
processing time
Set OL = CreateObject("Outlook.Application") ' New
Outlook application
Set EmailItem = OL.CreateItem(olMailItem) ' new
MailItem
FileName = ActiveSheet.Name & "1-City" &
ActiveWorkbook.Name ' create a filename on the fly
For lngLoop = 1 To Len(1 - City) ' error check for
unusable chars in the filename
TempChar = Mid(1 - City, y, 1)
Select Case TempChar
Case Is = "/", "\", "*", "?", """", "<", "", "/"
Case Else
SaveName = SaveName & TempChar
End Select
Next lngLoop
ActiveSheet.Cells.Copy ' copy the contents of the
ActiveSheet
Workbooks.Add ' create a new workbook
Selection.PasteSpecial Paste:=xlValues ' paste the
worksheet values into the new book
Selection.PasteSpecial Paste:=xlFormats ' and their
formats
ActiveWorkbook.SaveAs "C:\Temp" & SaveName ' temp

file
attachment location
ActiveWorkbook.ChangeFileAccess xlReadOnly ' make
access read only
With EmailItem ' with the newly created e-mail
.Subject = ActiveWorkbook.Name
.Body = "This is an example of a single worksheet
sent by VBa mail"
.To = "1-Depot"
.Importance = olImportanceNormal 'Or
olImportanceHigh Or olImportanceLow
.Attachments.Add "C:\Temp" & SaveName
.Send ' send the worksheet
End With
Kill "C:\Temp" & SaveName ' delete the temporary
attachment
ActiveWorkbook.Close False ' close down the workbook
without saving (single sheet)

Application.ScreenUpdating = True ' always remember

to
switch it back on!!

Set OL = Nothing ' clean down memory
Set EmailItem = Nothing

End Sub

.




.

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
Email one worksheet to email address on worksheet Veronica Johnson Excel Worksheet Functions 4 April 30th 10 01:04 PM
how do i email a single worksheet in excel 2007 LJ2 Excel Discussion (Misc queries) 1 March 24th 09 08:42 PM
Embed email address into worksheet Annie1904 Excel Discussion (Misc queries) 5 September 17th 08 05:47 PM
Email a single worksheet Sandy Excel Discussion (Misc queries) 8 April 28th 06 02:37 AM
emailing a single worksheet from a workbook fjfino Excel Worksheet Functions 4 December 5th 05 08:46 PM


All times are GMT +1. The time now is 09:00 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"