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

Hello,

I was wondering if anyone could help me. I am trying to get a code to copy
a worksheet (command button on one sheet [named home], the sheet I'm trying
to copy is hidden[named hidden]), paste special to a new worksheet with
formats and values, then emailing the new worksheet to a distribution list in
another cell (if this part is possible, if not I can enter the addresses by
hand), close/delete the new worksheet with out saving it, and return to the
'home' worksheet.

Thanks

Dave
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Emailing a worksheet

Hi Dave

Try this
Change this line to your distribution list

.Recipients.Add "GroupName"


Sub Mail_Hidden_Sheet()
'Working in 2000-2007
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set Sourcewb = ActiveWorkbook

'Copy the sheet to a new workbook
With Sourcewb.Sheets("hidden")
.Visible = True
.Copy
.Visible = False
End With

Set Destwb = ActiveWorkbook

'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
'We exit the sub when your answer is NO in the security dialog that you only
'see when you copy a sheet from a xlsm file with macro's disabled.
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With

'Change all cells in the worksheet to values if you want
With Destwb.Sheets(1).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False

'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Part of " & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.Recipients.Add "GroupName"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add Destwb.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
.Close SaveChanges:=False
End With

'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub





--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Dave M" wrote in message ...
Hello,

I was wondering if anyone could help me. I am trying to get a code to copy
a worksheet (command button on one sheet [named home], the sheet I'm trying
to copy is hidden[named hidden]), paste special to a new worksheet with
formats and values, then emailing the new worksheet to a distribution list in
another cell (if this part is possible, if not I can enter the addresses by
hand), close/delete the new worksheet with out saving it, and return to the
'home' worksheet.

Thanks

Dave

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
Emailing worksheet Tina Excel Worksheet Functions 2 January 22nd 10 08:13 PM
Emailing A Worksheet Trese Excel Worksheet Functions 2 October 19th 09 05:13 PM
Emailing a worksheet yellowcake Excel Discussion (Misc queries) 1 June 17th 06 11:54 AM
Emailing worksheet Craig Excel Discussion (Misc queries) 2 September 12th 05 05:52 PM
Emailing a worksheet Craig Excel Discussion (Misc queries) 0 May 13th 05 08:07 PM


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