View Single Post
  #12  
Old May 6th 08, 04:17 PM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,568
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.

Ads
 

Secured Loans - Mobile Phone - Loan - Credit Cards - Online Advertising