![]() |
| 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. |
|
|||||||
| Tags: attachment, automate, selection |
|
|
|
Thread Tools | Display Modes |
|
#11
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Get selection into textstring | Peter R.[_2_] | Outlook and VBA | 8 | December 6th 07 05:50 PM |
| Language selection does not take | ritter197 | Outlook - General Queries | 0 | October 23rd 06 11:35 PM |
| Contact selection | DCL | Outlook - Using Contacts | 5 | September 15th 06 03:06 AM |
| Message selection | Julieta Prandi | Add-ins for Outlook | 0 | March 30th 06 11:22 PM |
| Is it possible to automate this? | John 3:16 | Outlook - General Queries | 0 | March 27th 06 03:26 PM |