![]() |
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 |
|
#1
|
|||
|
|||
![]()
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 |
#2
|
|||
|
|||
![]()
It is all up to you. The line
Debug.Print objExplorer.CurrentFolder.Name can be split into dim Folder As Outlook.MAPIFolder set Folder = objExplorer.CurrentFolder Debug.Print Folder.Name That would be helpful if you are planning to access objExplorer.CurrentFolder more than once. In that case it makes sense to cache it in an explicitly declared variable rather than call objExplorer.CurrentFolder multiple times. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Carol G" wrote in message news:2PWqh.675494$R63.605586@pd7urf1no... 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 |
#3
|
|||
|
|||
![]()
Thank your for your time. I'm starting to get it.
Carol "Dmitry Streblechenko" wrote in message ... It is all up to you. The line Debug.Print objExplorer.CurrentFolder.Name can be split into dim Folder As Outlook.MAPIFolder set Folder = objExplorer.CurrentFolder Debug.Print Folder.Name That would be helpful if you are planning to access objExplorer.CurrentFolder more than once. In that case it makes sense to cache it in an explicitly declared variable rather than call objExplorer.CurrentFolder multiple times. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Carol G" wrote in message news:2PWqh.675494$R63.605586@pd7urf1no... 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 |
#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 |
#5
|
|||
|
|||
![]()
So , does that mean that .GetDefaultFolder(olFolderWhatever) creates an
explorer object for itself and then each time I access ..GetDefaultFolder(whatever) it creates a new temporary explorer object. So declaring one myself and pointing it at the folder is quicker but not necessary? I have a lot to learn. I am going to try out your code. Danke Schoen for your time. Carol "Michael Bauer [MVP - Outlook]" wrote in message .. . 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).Su bject 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 |
#6
|
|||
|
|||
![]() GetDefaultFolder doesn't create Explorers, but it returns a reference to a folder. As you can see, the function needs an argument for the requested folder, that is for each call the function has to check what folder you want to get and 'find' it. Obviously, it's faster to reuse the reference stored in a variable. So yes, it's quicker but not necessary. -- 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 19:53:47 GMT schrieb Carol G: So , does that mean that .GetDefaultFolder(olFolderWhatever) creates an explorer object for itself and then each time I access .GetDefaultFolder(whatever) it creates a new temporary explorer object. So declaring one myself and pointing it at the folder is quicker but not necessary? I have a lot to learn. I am going to try out your code. Danke Schoen for your time. Carol "Michael Bauer [MVP - Outlook]" wrote in message .. . 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).Su bject 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 |