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 - Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Tags: , ,

Automate attachment selection





 
 
Thread Tools Display Modes
  #11  
Old May 2nd 08, 09:15 PM posted to microsoft.public.outlook.program_forms
Marc[_3_]
external usenet poster
 
Posts: 3
Default Automate attachment selection

Hello,

This is the code I was referring to:

Quote:
Sub InsertFile()
' requires reference to Microsoft Outlook library
Dim objOL As Outlook.Application
Dim objInsp As Outlook.Inspector
Dim objMail As Outlook.MailItem
On Error Resume Next
Set objOL = GetObject(, "Outlook.Application")
Set objInsp = objOL.ActiveInspector
Set objMail = objInsp.CurrentItem
objMail.Attachments.Add "C:\data\myfile.txt"
Set objMail = Nothing
Set objInsp = Nothing
Set objOL = Nothing
End Sub



And the Excel file does not change. And it's location (in C drive) does not change either.
Ads
  #12  
Old May 6th 08, 04:17 PM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,162
Default Automate attachment selection

You'd want to use the events related to the Inspector window. Put the following code in the built-in ThisOutlookSession module, then run the Application_Startup procedure.


Dim WithEvents m_colInsp As Outlook.Inspectors
Dim WithEvents m_objInsp As Outlook.Inspector

Private Sub Application_Startup()
Set m_colInsp = Application.Inspectors
End Sub

Private Sub m_colInsp_NewInspector(ByVal Inspector As Inspector)
Set m_objInsp = Inspector
End Sub

Private Sub m_objInsp_Activate()
Dim objMail As Outlook.mailItem
If m_objInsp.CurrentItem.Class = olMail Then
Set objMail = m_objInsp.CurrentItem
If objMail.Size = 0 Then
' it's a new message
objMail.Attachments.Add "C:\Data\myfile.xls"
End If
End If
Set objMail = Nothing
Set m_objInsp = Nothing
End Sub


--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Marc" wrote in message ...
Hello,

This is the code I was referring to:

Quote:
Sub InsertFile()
' requires reference to Microsoft Outlook library
Dim objOL As Outlook.Application
Dim objInsp As Outlook.Inspector
Dim objMail As Outlook.MailItem
On Error Resume Next
Set objOL = GetObject(, "Outlook.Application")
Set objInsp = objOL.ActiveInspector
Set objMail = objInsp.CurrentItem
objMail.Attachments.Add "C:\data\myfile.txt"
Set objMail = Nothing
Set objInsp = Nothing
Set objOL = Nothing
End Sub



And the Excel file does not change. And it's location (in C drive) does not change either.

  #13  
Old May 15th 08, 05:03 PM posted to microsoft.public.outlook.program_forms
Marc[_3_]
external usenet poster
 
Posts: 3
Default Automate attachment selection

Hello suemvp,

Thank you so much for your help. The code works perfectly. I greatly appreciate it for taking your time to help me.

I also managed to learn a few things about using the built-in VB Editor.

Best Regards,

Starbuzz
 




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
Get selection into textstring Peter R.[_2_] Outlook and VBA 8 December 6th 07 04:50 PM
Language selection does not take ritter197 Outlook - General Queries 0 October 23rd 06 10:35 PM
Contact selection DCL Outlook - Using Contacts 5 September 15th 06 02:06 AM
Message selection Julieta Prandi Add-ins for Outlook 0 March 30th 06 10:22 PM
Is it possible to automate this? John 3:16 Outlook - General Queries 0 March 27th 06 02:26 PM


All times are GMT +1. The time now is 12:05 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.
Neopets Cheats, Games and Neopoints - Credit Cards - Mortgages - Loans - Free Ringtone