send sheet as attachment

T

TBolt

I want to send a active work sheet in excel as an attachment for only a
certain workbook (BookA). I created a macro button on the toolbar, using
the default happyface as the icon, and assigned the macro below to that
button. I saved that macro on that workbook (BookA). My problem is that no
matter what workbook I have open if I click the happy face icon and it will
run that macro. I do not want the macro to run on anywork book open only
that certain one (BookA). What code do I need to add where that macro only
runs when that workbook (BookA) is open and not workbook BookB, C, D,.....)
open?
I do not want people to have a different workbook open and inadverently
press that button. I thought abought doing a command button on each
worksheet but then I would want to strip the button and macro from the
worksheet that will be sent before it is sent so that the reciepment would
not have the command button and macro on the file that they get.

'Name of macro mailsheet
Sub mailsheet()
'Copies the active sheet to a new workbook
ActiveSheet.Copy
'Saves new workbook with new worksheet name from org. filename 'and adds the
text "Part of"
'to the front of worksheet the will be emailed.
ActiveWorkbook.SaveAs "Part of " & ThisWorkbook.Name _
& " " & strdate & ".xls"
'Sends to the email to address below and with the "Tester" as the subject
line.
ActiveWorkbook.sendmail "(e-mail address removed)
'Changes the file that is emailed to read only in MY Documents.
ActiveWorkbook.ChangeFileAccess xlReadOnly
'Delets the temp file "part of" located in my documents.
Kill ActiveWorkbook.FullName
'Closes the file that was opened to send
ActiveWorkbook.Close True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top