LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Email a file as an attachment in Outlook 2000 using Excel VB macro

Does anyone have Excel VBA code to email a file as an attachment in Outlook
2000 using a variable? The file name is not static. It changes every month.
Please note the code below, which is not executed, where it reads:
'.Attachments.Add ("C:\test.txt"). I want to use a variable instead of the
hard-coded path and file "C:\test.txt".


Sub Mail_workbook_Outlook()
'This example sends the last saved version of each open workbook
'You must add a reference to the Microsoft outlook Library
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim Wb As Workbook
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "Monthly File Attachment"
.Body = "Hi there"
For Each Wb In Application.Workbooks
If Wb.Windows(1).Visible And Wb.Path < "" Then
.Attachments.Add Wb.FullName
End If
Next
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 
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
Send an email attachment (pdf file) from Excel 2003 using Outlook Express [email protected] Excel Programming 6 November 16th 06 03:02 PM
Excel Spreadsheet email attachment unable to open in Outlook Expr. Joanne from Tiffin, Oh Excel Discussion (Misc queries) 1 April 23rd 05 12:21 AM
Email Excel File Automatically using Outlook 2000 Niraj Excel Programming 3 September 24th 04 11:09 AM
Send current Excel File as an attachment using Outlook 2000 ZABU Excel Programming 3 May 28th 04 04:50 AM
Email Attachment from Excel using Outlook. Pyball[_3_] Excel Programming 2 December 17th 03 07:08 PM


All times are GMT +1. The time now is 05:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"