excel course tate modern - emailing excel spreadsheet using
Microsoft Office TrainingThe UK's Number 1 for Microsoft Office Training Sitemap add this page to your favourites/bookmarksBookmark page
 
view a printable version of this pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » excel course tate modern - Emailing an excel spreadsheet using vba

excel course tate modern - Emailing an excel spreadsheet using vba

resolvedResolved · Low Priority · Version Standard

replyReplyThu 29 Nov 2007, 10:46Delegate Samantha said...

Emailing an excel spreadsheet using vba

i have a macro that formats a file, but after formatting, i want to then email that file to a specific email address.

i tried to record the macro when doing it but no code was displayed in vba

can you please help?
thanks
sam

For upcoming training course dates see: Pricing & availability

replyReplyMon 10 Dec 2007, 12:17Trainer Carlos said...

RE: emailing an excel spreadsheet using vba

Hi Sam

There is a simple routine that sends the active Workbook to an e-mail recepient. This is:

Sub EMailActiveWorkbook()

ActiveWorkbook.SendMail Recipients:="someone@home.com", Subject:="Our Excel Work For " & Format (Date, "dd/mmm/yy")

End Sub


The above code can be entered as a macroto be called from the Fromat macro, or you could add the code to your Fromat macro

Hope this helps

Carlos

replyReplyMon 10 Dec 2007, 13:51Delegate Samantha said...

RE: emailing an excel spreadsheet using vba

Hi carlos,
this didnmt seem to work.

error message came up saying "run time error 1004, method SendMail of object _Workbook failed"

any ideas? perhaps something that i dont have loaded into my excel?

thanks
sam

replyReplyMon 10 Dec 2007, 14:24Trainer Carlos said...

RE: emailing an excel spreadsheet using vba

Hi Sam

I ran the macro above on its own both from the code window and as a button in the toolbar.

In both cases it worked perfectly.

So I'm wondering if there is a problem with your company's Outlook settings

OR

if you are trying to refer to the Workbook to be sent by name.

If so the workbooks name and path have to be absolutely accurate otherwise you get a 1004 error for trying to e-mail a workbook that doesn't exist

Carlos

replyReplyMon 10 Dec 2007, 14:37Delegate Samantha said...

RE: emailing an excel spreadsheet using vba

hi carlos,
here is my code

'AUTOFIT COLUMNS
Cells.Select
Selection.Columns.AutoFit
Range("A1").Select

'go back to detailed sheet and get to A1
wsD.Select
Range("A1").Select
ActiveCell.FormulaR1C1 = Time


Sheets(ActiveSheet.Name).Move
'**CHANGE THIS DIRECTORY TO THE PLACE TO SAVE THE REPORT
ChDir "D:\DMG"
directory = "D:\DMG\"

'file name
filenamesave = "Automated " & FormatDateTime(Date, vbLongDate)

ActiveWorkbook.SaveAs Filename:=directory & filenamesave & ".xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False

'send as an email - addition 10/12/07
ActiveWorkbook.SendMail Recipients:="sam@datam.co.uk", Subject:=filenamesave

'close workbook
ActiveWorkbook.Close

so you can see that i move the worksheet, then save the workbook as a file name, then try to send it as an email.
i CAN do this manually so i'm not sure there is anything wrong with excel.

would it mnake a difference that i am using excel 2003?

thanks
sam

replyReplyMon 10 Dec 2007, 15:17Trainer Carlos said...

RE: emailing an excel spreadsheet using vba

Sam

I assume that everything works OK except the e-mail part of the code.

I took you e-mail line and declared FileNameSave as a String variable and used your text in it.

I ran the code and created a e-mail in the outbox of my Outlook with your FileNameSave value as subject.

Which means that your Outlook might be set to not allowing other applications to send an email.

On my system I get a warning informing me that an external program is trying to send an e-mail and is that OK.

You may need you IT department to change the settings on your computer to allow this.

Carlos

replyReplyTue 11 Dec 2007, 14:57Delegate Samantha said...

RE: emailing an excel spreadsheet using vba

ok thanks carlos,
have now established that it does NOT work on my laptop but DOES work on other pcs.
will have to get to the bottom of what is going on with my laptop.
so thank you very much for your help with this
cheers,
sam

 

 

forum postHow do I change the colour of the gridlines in a work book?

» Forum post: Gridline Colours


Rate this page:
2.2/5 (213 votes cast)
Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses
Microsoft Certified Partner
Security Seal verified by visa, mastercard securecard

Mini sitemap. These are the main areas of our web site. Full sitemap.

Management training

Professional Skills courses
Project Management Course London
Project Management Courses London
Project Management Training London
Project Management Training
Project Seminar
Project Seminars
Time Management Course London
Time Management London
Time Management Courses London
Time Management Training London
Introduction to Finance course
Assertiveness Skills course
Effective Communications Skills training
Presentation Skills London

Training Formats

Public scheduled courses
On-site training
Closed company courses

Consultancy
Application Development

Blogs

Excel Training
MS Project Training
Microsoft Training Blog

Version differences

Office 2010 vs 2007
MS Project version differences

Training Information

London Computer Training
Computer Training London
Docklands Training Courses
Docklands Training London

Training venues London
Client list
FAQ
Pricing and availability
Course details / Syllabus

Training Articles
Training Information

Microsoft training

Microsoft Office training
& IT Applications

Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training
MS Project courses
MS Project training
Outlook courses
PowerPoint courses
PowerPoint training
VBA courses
Word courses
Microsoft.training
(more...)

Excel Training

Excel courses
Excel Training Courses Medway
Autonumber in Excel
Microsoft Excel training
Basic Excel Courses
Basic Excel Course
Basic Excel Training

Interested in MS Access training?

Access courses
Microsoft Access training
Microsoft access courses
Microsoft training access course
Microsoft+access+training
Access courses in london

Training provider

Training providers
IT training companies
IT training providers
Management Training providers
Management Training provider

Event history, feedback results
Events in 2012 · 2011 · 2010 · More

See also

Crystal Reports training