excel course tate modern - emailing excel spreadsheet using
Microsoft Office Training verified by visa - mastercard securecode about microsoft training company london ukadd this page to your favourites/bookmarksAdd to favourites
view a printable version of this pagePrintable version
email this page to somebodyEmail this page
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

The UK's most regular instructor-led training courses.
Training information: excel course tate modern · Advanced.excel · VBA courses London

resolvedResolved · Low Priority · Version Standard

Emailing an excel spreadsheet using vba

Samantha has attended:
Excel VBA course

by - delegate Samantha [21 posts] (2007 Nov 29 Thu, 10:46) replyReply

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

Excel VBA 2 day course
Version Date Location Places
available
Book Next place rate:
Card Invoice
2007 2008 Dec 11 Thu + 12 Fri Bayswater 3 book now £525 £545
2007 2009 Jan 8 Thu + 9 Fri Bloomsbury 7 book now £450 £475
2003 2009 Jan 22 Thu + 23 Fri Southwark 4 book now £475 £485
2003 2009 Jan 29 Thu + 30 Fri Bayswater 6 book now £450 £485
2007 2009 Feb 5 Thu + 6 Fri Bloomsbury 7 book now £450 £475
2003 2009 Feb 19 Thu + 20 Fri Southwark 8 book now £275 £399
Full Schedule: See all 33 Excel VBA course dates.
Bookings currently available until 26th November 2009.

RE: emailing an excel spreadsheet using vba

by - trainer Carlos gold contributer[479 posts] (2007 Dec 10 Mon, 12:17) replyReply

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

RE: emailing an excel spreadsheet using vba

by - delegate Samantha [21 posts] (2007 Dec 10 Mon, 13:51) replyReply

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

RE: emailing an excel spreadsheet using vba

by - trainer Carlos gold contributer[479 posts] (2007 Dec 10 Mon, 14:24) replyReply

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

RE: emailing an excel spreadsheet using vba

by - delegate Samantha [21 posts] (2007 Dec 10 Mon, 14:37) replyReply

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

RE: emailing an excel spreadsheet using vba

by - trainer Carlos gold contributer[479 posts] (2007 Dec 10 Mon, 15:17) replyReply

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

RE: emailing an excel spreadsheet using vba

by - delegate Samantha [21 posts] (2007 Dec 11 Tue, 14:57) replyReply

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


Related articles

· How to Create Better Excel Spreadsheets: Part Three
· Microsoft Excel Training Courses or Consultants: Which Is Better For Your Company?
· Why Should I Learn Visual Basic in Excel?
· From the Classroom to the Corporate World
· Do You Really Need Excel VBA Training?

Excel tip:

Use shortcut keys to select rows or columns

Most users use the mouse to select rows or columns. It may be more convenient to use keyboard shortcuts to do that.

The shortcut key combination to select an entire row is Shift+Spacebar.

The shortcut key combination to select an entire column is Ctrl+Spacebar.

These are pretty easy to remember as the spacebar looks like a long row (or column if you're looking at it sideways). Remember that Ctrl, beginning with C, selects columns and Shift, by a process of elimination, the rows.

View all Excel hints and tips

Rate this page:
4.0/5 (3 votes cast)
Institute of IT Training - Accredited Training Provider Microsoft Certified Partner
microsoft office
Microsoft Office Specialist Authorised Testing Centre (MOS and MCAS)

Prodigy Platinum Learning Partner

Institute of IT Training - Accredited Training Provider Association of Computer Trainers Valid HTML 4.01 Transitional
Valid CSS Markup

secure online payments - visa - mastercard

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

Training by application Main information pages See also

Access courses
DreamWeaver courses
Excel courses
MS Project courses
Outlook courses
PowerPoint courses
VBA courses
Word courses
(more...)

Public scheduled courses
On-site training
Closed company courses

Microsoft Office training
Pricing and availability
Training schedule
Training venues

Access training
Dreamweaver training
Excel training
MS Project training
PowerPoint training

London Computer Training
Computer Training London

Microsoft Access training
Microsoft Excel training
Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training

Time Management Course London

Interested in Access training? Please see the following pages:
microsoft access courses · microsoft training access course
microsoft+access+training · access courses in london

Training Information

Training Articles

AddThis Social Bookmark Button What's this?
Add to Del.icio.us Add to Facebook Add to Digg Add to Reddit Add to Google Add to Yahoo Add to Diigo Add to Mr. Wong Add to Linkarena Add to Power Oldie Add to Folkd Add to Jumptags Add to Upchuckr Add to Simpy Add to StumbleUpon Add to Slashdot Add to Netscape Add to Furl Add to Spurl Add to Blinklist Add to Blogmarks Add to Technorati Add to Newsvine Add to Blinkbits Add to Ma.Gnolia Add to Smarking Add to Netvouz