A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Tags: , , , ,

Automatically adding attachments and sending them





 
 
Thread Tools Display Modes
  #1  
Old December 22nd 06, 12:33 PM posted to microsoft.public.outlook.program_vba
DannyJ
external usenet poster
 
Posts: 10
Default Automatically adding attachments and sending them

Hi folks,

I am trying to create a macro that at the push of a button creates an email
with a subject of "Cims data" picks up and attaches all the files from a
predefined, folder, and sends it to a predefined email address.

i.e. no need to manually add the files, the subject or the recipient.

Any ideas? I know a little VBA in Excel but nothing about Outlook, though I
assume there are similarities.

Many thanks,

A
Ads
  #2  
Old December 22nd 06, 05:01 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 3,778
Default Automatically adding attachments and sending them

The only tricky part of what you want to do is to know how many files to
attach are in a specific folder and how to get those files. For that you
will need to get the folder, get the files count in the folder and add each
item. For simplicity I'll show some code that adds two pre-determined files
as attachments.

Sub Foobar()
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oMail As Outlook.MailItem

Set oApp = CreateObject("Outlook.Application")
Set oNS = oApp.GetNameSpace("MAPI")
oNS.Logon

Set oMail = oApp.CreateItem(olMailItem)
With oMail
.Subject = "Cims data"
.Body = "Some body text"
.Attachments.Add "c:\myFolder\File1.xls"
.Attachments.Add "c:\myFolder\File2.xls"
.Recipients.Add "
.Recipients.ResolveAll
.Send
End With
End Sub

Accessing Recipients and sending may fire the Outlook object model guard if
running the code from Excel. For your options with that see
http://www.outlookcode.com/d/sec.htm

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"DannyJ" wrote in message
...
Hi folks,

I am trying to create a macro that at the push of a button creates an
email
with a subject of "Cims data" picks up and attaches all the files from a
predefined, folder, and sends it to a predefined email address.

i.e. no need to manually add the files, the subject or the recipient.

Any ideas? I know a little VBA in Excel but nothing about Outlook, though
I
assume there are similarities.

Many thanks,

A


  #3  
Old January 1st 07, 08:58 PM posted to microsoft.public.outlook.program_vba
Dan Guzman
external usenet poster
 
Posts: 1
Default Automatically adding attachments and sending them

I've tried your exact code, in a Microsoft Access module, with the Outlook
reference added, and get the following error message on the attachment line:

'Operation is not supported for this type of Object'

What am I missing?

Dan

"Ken Slovak - [MVP - Outlook]" wrote:

The only tricky part of what you want to do is to know how many files to
attach are in a specific folder and how to get those files. For that you
will need to get the folder, get the files count in the folder and add each
item. For simplicity I'll show some code that adds two pre-determined files
as attachments.

Sub Foobar()
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oMail As Outlook.MailItem

Set oApp = CreateObject("Outlook.Application")
Set oNS = oApp.GetNameSpace("MAPI")
oNS.Logon

Set oMail = oApp.CreateItem(olMailItem)
With oMail
.Subject = "Cims data"
.Body = "Some body text"
.Attachments.Add "c:\myFolder\File1.xls"
.Attachments.Add "c:\myFolder\File2.xls"
.Recipients.Add "
.Recipients.ResolveAll
.Send
End With
End Sub

Accessing Recipients and sending may fire the Outlook object model guard if
running the code from Excel. For your options with that see
http://www.outlookcode.com/d/sec.htm

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"DannyJ" wrote in message
...
Hi folks,

I am trying to create a macro that at the push of a button creates an
email
with a subject of "Cims data" picks up and attaches all the files from a
predefined, folder, and sends it to a predefined email address.

i.e. no need to manually add the files, the subject or the recipient.

Any ideas? I know a little VBA in Excel but nothing about Outlook, though
I
assume there are similarities.

Many thanks,

A



  #4  
Old January 2nd 07, 05:00 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 3,778
Default Automatically adding attachments and sending them

What line do you get the error on?

I'm not sure about that error, attaching a file is certainly supported for
an email item, so I don't know why you would get that.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dan Guzman" Dan wrote in message
...
I've tried your exact code, in a Microsoft Access module, with the Outlook
reference added, and get the following error message on the attachment
line:

'Operation is not supported for this type of Object'

What am I missing?

Dan


  #5  
Old January 3rd 07, 04:58 PM posted to microsoft.public.outlook.program_vba
Dan Guzman
external usenet poster
 
Posts: 1
Default Automatically adding attachments and sending them

As I stated in the first post, the error is on the attachment line. Repeated
below:

.Attachments.Add "C:\Temp\Test.txt"

I've tried changing to late binding, and still get the same error mesage.
If I remove this one line, the code works fine (email sent or displayed) .
This has been very frustrating, since all online help seems to give the same
code as an example, and errors are related to binding and other things.


"Ken Slovak - [MVP - Outlook]" wrote:

What line do you get the error on?

I'm not sure about that error, attaching a file is certainly supported for
an email item, so I don't know why you would get that.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dan Guzman" Dan wrote in message
...
I've tried your exact code, in a Microsoft Access module, with the Outlook
reference added, and get the following error message on the attachment
line:

'Operation is not supported for this type of Object'

What am I missing?

Dan



  #6  
Old January 3rd 07, 07:44 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 3,778
Default Automatically adding attachments and sending them

I'm sure it's frustrating. I've never had any problems adding attachments
and I use code like that all the time.

The only things I can think of offhand are to see if the same code when run
as an Outlook macro from within Outlook fires the same error, try the code
on another machine to see if the problem is machine specific and to test an
alteration of the code to change that line to instantiate an Attachment
object:

Dim oAttach As Outlook.Attachment
Set oAttach = .Attachments.Add "C:\Temp\Test.txt"

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dan Guzman" wrote in message
...
As I stated in the first post, the error is on the attachment line.
Repeated
below:

.Attachments.Add "C:\Temp\Test.txt"

I've tried changing to late binding, and still get the same error mesage.
If I remove this one line, the code works fine (email sent or displayed) .
This has been very frustrating, since all online help seems to give the
same
code as an example, and errors are related to binding and other things.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I turn off automatically adding email contacts to Outlook? RLang Outlook - Using Contacts 2 December 19th 06 10:24 PM
01/01/1601 Anniversary Date adding to Contacts automatically John Venables Outlook - Using Contacts 2 May 21st 06 02:38 PM
Prevent outlook from automatically adding meeting requests Nathan Toone Outlook - Calandaring 6 April 17th 06 02:48 PM
Automatically adding PST files to Outlook profile via logon script Brian Steele Outlook - Installation 2 March 17th 06 01:39 PM
Adding Buffer Time Automatically to Accepted Meetings Kristy Outlook - Calandaring 0 March 7th 06 11:19 PM


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2008 Outlook Banter, part of the NewsgroupBanter project.
The comments are property of their posters.
Pet Insurance - Article submission - Credit Cards - Montana Music - Free Credit Reports