![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
#4
|
|||
|
|||
![]() Carol, one might say that's up to you. Actually you wouldn't need any variable, but the root object. For instance, for the Inbox' name and its first Items' subject you could write: Debug.Print Application.GetNamespace("mapi").GetDefaultFolder( olFolderInbox).Name Debug.Print Application.GetNamespace("mapi").GetDefaultFolder( olFolderInbox).Items(1).Subject As you can see, this quickly would become confused and it's a lot more work to write the code. And each call takes time! E.g., in VBA t1 needs on my PC for about 1800 items 3.5 seconds, t2 only 1.4 seconds. Private Declare Function GetTickCount Lib "kernel32" () As Long Private time1 As Long Private time2 As Long Public Sub t1() Dim i& time1 = GetTickCount For i = 1 To Application.ActiveExplorer.CurrentFolder.Items.Cou nt Debug.Print Application.ActiveExplorer.CurrentFolder.Items(i). Subject Next time2 = GetTickCount Debug.Print (time2 - time1) / 1000 End Sub Sub t2() Dim i& Dim Items As Outlook.Items time1 = GetTickCount Set Items = Application.ActiveExplorer.CurrentFolder.Items For i = 1 To Items.Count Debug.Print Items(i).Subject Next time2 = GetTickCount Debug.Print (time2 - time1) / 1000 End Sub So I'd say, whenever you need to access an object more than once then use a variable and store the reference to the object. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook Keep your Outlook categories organized! http://www.shareit.com/product.html?...4&languageid=1 (German: http://www.VBOffice.net/product.html?pub=6) Am Tue, 16 Jan 2007 02:32:30 GMT schrieb Carol G: I'm trying to wrap my head around the outlook objects. I'm sure this is a stupid question but I'm having trouble grasping when I need to declare objects and when I don't. Why don't I need a MapiFolder object to view properties such as Name of the Current Folder below? Confused.... Carol Sub TestOfExpolorerObject() Dim objApp As Outlook.Application Dim objNms As Outlook.NameSpace Dim objExplorer As Outlook.Explorer Set objApp = CreateObject("Outlook.Application") Set objNms = objApp.GetNamespace("Mapi") Set objExplorer = objApp.ActiveExplorer Debug.Print objExplorer.CurrentFolder.Name Set objApp = Nothing Set objNms = Nothing Set objExplorer = Nothing End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to add a UserProperty to a MAPIFolder? | Jeff | Outlook and VBA | 4 | November 8th 06 10:10 PM |
Help : Outlook.MAPIFolder, VBA macros | lerneree | Outlook - General Queries | 1 | September 6th 06 01:07 PM |
Help -Outlook.MAPIFolder, VBA macros | lerneree | Outlook and VBA | 1 | September 6th 06 12:59 PM |
Outlook.MAPIFolder, VBA macros | lerneree | Outlook - Using Forms | 0 | September 6th 06 10:18 AM |
MapiFolder Items ItemChange is not firing | AtulSureka | Outlook - Using Forms | 1 | February 6th 06 04:32 PM |