![]() |
| 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: event, selectionchange |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi folks,
I have a quick (yet probably easy question). I've done some VBA in excel for the generation of engineering calculation spreadsheets but this is my first kick at VBA in Outlook. I'm trying to create a routine where I can click a message in my Inbox (or elsewhere) and save this message to a msg file in a specific locaiton. The file format and path for the save will be based on the contents of the email subject, the send date, who it was from, etc. I have this part of the routine working fine. I click a message, then click the menu button, my form pops up it automatically fills in the fields for date, subject etc. I can then click a save button and the message will be saved to a msg file with the appropriate filename. The next thing I would like to do is be able to leave the form open and switch to a different message. When I switch, I'd like the date, subject, sender info to be updated with the new message selected. From what I can tell I need to use a selectionchange event to trap this. I've never really worked with class modules before. From what I can tell I have to create a new class module. I found this code on the net and added it to the class module: Dim WithEvents myolexp As Outlook.Explorer Private Sub Application_Startup() Set myolexp = Application.ActiveExplorer End Sub Private Sub myOlExp_Close() ' Need to do this so Outlook exits properly. Set myolexp = Nothing End Sub Private Sub myOlExp_SelectionChange() MsgBox "SelectionChange" frmSaveMessage.lbltest.Caption = "Changed" End Sub When I add this code to ThisOutlookSession, the event triggers everytime. I want it so that the event only triggers when I have my form opened. HELP! Thanks, AB |
| Ads |
|
#2
|
|||
|
|||
|
When dealing with Outlook items in their own windows, it's best to trap the
Inspectors collection which gets populated by each window that opens. See my blog for an example: Getting a Handle on Your E-mails with VBA: http://blogs.officezealot.com/legaul...cles/2224.aspx Taking it even further is this sample code: http://www.slovaktech.com/code_sampl...spectorWrapper This allows you to have separate "threads" for each item that opens, so you can trap events for them individually. This concept can be a little tough to consume, but here's an excellent sample project that you can examine and even run to help illustrate it: http://www.microeye.com/resources/itemsCB.htm -- Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "A. Blundon" wrote: Hi folks, I have a quick (yet probably easy question). I've done some VBA in excel for the generation of engineering calculation spreadsheets but this is my first kick at VBA in Outlook. I'm trying to create a routine where I can click a message in my Inbox (or elsewhere) and save this message to a msg file in a specific locaiton. The file format and path for the save will be based on the contents of the email subject, the send date, who it was from, etc. I have this part of the routine working fine. I click a message, then click the menu button, my form pops up it automatically fills in the fields for date, subject etc. I can then click a save button and the message will be saved to a msg file with the appropriate filename. The next thing I would like to do is be able to leave the form open and switch to a different message. When I switch, I'd like the date, subject, sender info to be updated with the new message selected. From what I can tell I need to use a selectionchange event to trap this. I've never really worked with class modules before. From what I can tell I have to create a new class module. I found this code on the net and added it to the class module: Dim WithEvents myolexp As Outlook.Explorer Private Sub Application_Startup() Set myolexp = Application.ActiveExplorer End Sub Private Sub myOlExp_Close() ' Need to do this so Outlook exits properly. Set myolexp = Nothing End Sub Private Sub myOlExp_SelectionChange() MsgBox "SelectionChange" frmSaveMessage.lbltest.Caption = "Changed" End Sub When I add this code to ThisOutlookSession, the event triggers everytime. I want it so that the event only triggers when I have my form opened. HELP! Thanks, AB |
|
#3
|
|||
|
|||
|
Thanks for the reply.
Your reply seems to deal with outlook items that have been opened (i.e. by double clicking an email and opening the viewer). In my case, it is simply selecting the messages in the inbox (without viewing the message contents). As part of my routine I've used the following code to extract the various parts of the message I need: Set objExplorer = objApplication.ActiveExplorer Set objSelection = objExplorer.Selection Set obj1stSelectedMessage = objSelection.Item(1) That way, i'll be processing the first selected item. AB |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Outlookscript with event | robert@getto.dk | Outlook - Using Forms | 4 | February 23rd 06 02:20 PM |
| lose onupdate event | jim | Add-ins for Outlook | 0 | February 16th 06 06:21 PM |
| Event handling? | mishra.basant@gmail.com | Add-ins for Outlook | 0 | January 25th 06 02:40 PM |
| Event handling? | mishra.basant@gmail.com | Add-ins for Outlook | 0 | January 25th 06 02:40 PM |
| Event Banners | Fishers | Outlook - Calandaring | 4 | January 17th 06 11:23 PM |