Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 18th, 2006, 07:08 AM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Automatically attach Excel spreadsheet to Email

I am at work and made a macro to do some simple automation of some daily reports I have to do. Everyday I have to send this report to one person and CC it to 3 different people. I wanted to include this in the current Macro.

Is there some way in the code to add this so that it automatically opens Microsoft Outlook and makes this an attachment?

Thanks,

~J
 
Old July 22nd, 2006, 01:42 AM
Authorized User
 
Join Date: Jul 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I hope that it help You resolve your problem:
Sub POCZTA0()
Dim myattachment
Dim olNs As Object
Dim olMailItem
Dim olMail As Object
Dim olApp As Object
Dim ATTACH1 As String


ATTACH1 = Application.GetOpenFilename("Text Files (*.*), *.*")
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
olNs.Logon
Set olMail = olApp.CreateItem(olMailItem)
olMail.Display

olMail.To = "[email protected]"
olMail.CC = "[email protected];" & "[email protected];" & "[email protected];"
'olMail.BCC =
olMail.Subject = "Your subject"
olMail.Body = vbCr & vbCr & "Your body text" & vbCr & vbCr

Set myattachment = olMail.Attachments
myattachment.Add ATTACH1
olMail.Send
olNs.Logoff
Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
End Sub
BR/
Kazik

 
Old August 1st, 2006, 08:48 AM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry for taking so long to respond back, thanks for the help!

When I try to use the code below, is it supposed to just allow me to pick what I want to attach? Is there anyway to have it just pick the file that I am already in?

ATTACH1 = Application.GetOpenFilename("Text Files (*.*), *.*")

Thanks,

~J
 
Old August 1st, 2006, 12:15 PM
Authorized User
 
Join Date: Jul 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I suppose that code (POCZTA0)is in file which You want send.
If yes, try it.
ATTACH1 = ThisWorkbook.FullName






Similar Threads
Thread Thread Starter Forum Replies Last Post
attach excel content to emails,based on criteria miracles Excel VBA 0 May 21st, 2007 09:45 PM
send an email to someone automatically crmpicco Classic ASP Basics 10 March 3rd, 2005 06:13 PM
send an email to someone automatically crmpicco VB How-To 1 February 25th, 2005 08:59 AM
Attach images to email kosla78 Classic ASP Basics 0 September 9th, 2003 03:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.