Djblois
05-03-2007, 12:43 PM
I use code to send out the Activeworkbook or the activeworksheet depending on what the user wants but now I am trying to set it up to send only what the user has selected. Preferably in the email if possible, if not as an attachment. here is the code I am trying:
Dim OL As Object
Dim EmailItem As Object
Dim FileName As String
Dim y As Long
Dim TempChar As String
Dim SaveName As String
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
FileName = ActiveSheet.Name & " - " & ActiveWorkbook.Name
For y = 1 To Len(FileName)
TempChar = Mid(FileName, y, 1)
Select Case TempChar
Case Is = "/", "\", "*", "?", """", "<", ">", "|", ":"
Case Else
SaveName = SaveName & TempChar
End Select
Next y
Selection.Copy
Set WB(1) = ActiveWorkbook
WB(1).SaveAs SaveName
WB(1).ChangeFileAccess xlReadOnly
With EmailItem
.Attachments.Add WB(1).FullName
.Display
End With
Kill WB(1).FullName
WB(1).Close False
Dim OL As Object
Dim EmailItem As Object
Dim FileName As String
Dim y As Long
Dim TempChar As String
Dim SaveName As String
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
FileName = ActiveSheet.Name & " - " & ActiveWorkbook.Name
For y = 1 To Len(FileName)
TempChar = Mid(FileName, y, 1)
Select Case TempChar
Case Is = "/", "\", "*", "?", """", "<", ">", "|", ":"
Case Else
SaveName = SaveName & TempChar
End Select
Next y
Selection.Copy
Set WB(1) = ActiveWorkbook
WB(1).SaveAs SaveName
WB(1).ChangeFileAccess xlReadOnly
With EmailItem
.Attachments.Add WB(1).FullName
.Display
End With
Kill WB(1).FullName
WB(1).Close False