toolbar
Main Topics
Browse All Topicsi want to open an specific worksheet and click on a button inside excel and run this code below......how do i do this?
Sub Mail_ActiveSheet()
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
ActiveSheet.Copy
Set Destwb = ActiveWorkbook
Destwb.Sheets(1).UsedRange
'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.Appl
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
With Destwb
.SaveAs TempFilePath & TempFileName & ".xls"
On Error Resume Next
With OutMail
.Attachments.Add Destwb.FullName
.Display
End With
On Error GoTo 0
.Close SaveChanges:=False
End With
'Delete the file you have send
Kill TempFilePath & TempFileName & ".xls"
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Click on the Record Macro button (near the bottom left corner of the status bar) and choose to save it in the Persomal Macro workbook. If you don't already have one, this will create one for you. Then click the button again to stop recording.
Now press Alt+f11 to open the VBEditor.
Locate the Personal.xlsb workbook in the Project Explorer window (top left corner of the VBEditor), right click it and choose Insert-Module.
Paste your code above into the blank window that appears.
Then customise the QAT as I mentioned earlier.
Finally, close Excel and when prompted choose Yes to save changes to the Personal.xlsb workbook.
HTH
Rory
Business Accounts
Answer for Membership
by: roryaPosted on 2009-11-05 at 08:25:05ID: 25751078
Do you mean a button in the worksheet, or a button on a toolbar?