Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Send an email attachment (pdf file) from Excel 2003 using Outlook Express | Excel Programming | |||
Excel Spreadsheet email attachment unable to open in Outlook Expr. | Excel Discussion (Misc queries) | |||
Email Excel File Automatically using Outlook 2000 | Excel Programming | |||
Send current Excel File as an attachment using Outlook 2000 | Excel Programming | |||
Email Attachment from Excel using Outlook. | Excel Programming |