View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Conditional Sheet Attachment

ActiveWorkbook.SaveAs "C:\" & sStr & ".xls", _
FileFormat:=xlWorkbookNormal


saves it as a workbook if you are in Excel and xlWorkbookNormal is a defined
constant. If not, try changing the argument to its constant value
? xlworkbooknormal
-4143


--
Regards,
Tom Ogilvy

Todd Huttenstine wrote in message
...
it worked but the file is not an Excel file and when I
opened it it does not work.
-----Original Message-----
I will have to assume that objMessage has an Attachments

collection:

If so, it would be something like:

Option Explicit
Private Sub CommandButton1_Click()
Dim sStr as String
sStr = Listbox1.Value
worksheets(sStr).Copy
ActiveWorkbook.SaveAs "C:\" & sStr & ".xls", _
FileFormat:=xlWorkbookNormal
ActiveWorkbook.Close SaveChanges:=False
Dim objSession As Object, objMessage As Object,
objOneRecip As Object
Set objSession = CreateObject("MAPI.Session")
objSession.Logon
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "Stats"
objMessage.Text = ""
'Set objOneRecip = objMessage.Recipients.Add
'objOneRecip.Name = "
'objOneRecip.Type = 1
'objOneRecip.Resolve
objMessage.Attachments.Add "C:\" & sStr & ".xls"
objMessage.Send showDialog:=True
objSession.Logoff
On Error Resume Next
kill "C:\" & sStr & ".xls"
On Error goto 0
End Sub

--
Regards,
Tom Ogilvy

Todd Huttenstine

wrote in message
...
Tom, that worked. Thank you. Below is the modified

code.
Combobox1 contains sheet names. I need for it to look

in
Combobox1, and attach that sheet to the email. How

would
I do this? For example the value "Todd Huttenstine" is

in
combobox1. Therefore I need for it to attach

sheet "Todd
Huttenstine" to the email.


Option Explicit
Private Sub CommandButton1_Click()
Dim objSession As Object, objMessage As Object,
objOneRecip As Object
Set objSession = CreateObject("MAPI.Session")
objSession.Logon
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "Stats"
objMessage.Text = ""
'Set objOneRecip = objMessage.Recipients.Add
'objOneRecip.Name

= "
'objOneRecip.Type = 1
'objOneRecip.Resolve
objMessage.Send showDialog:=True
objSession.Logoff


End Sub



.