| Code level: intermediate Code area: Outlook Form Design Printer Friendly Version | ||
| Title: Get Public Folder | ||
| Description: This is an ammendment to Sue's GetFolder function for outlook forms. It's purpose is that it will return a known public folder regardless of language settings. GetFolder doesnt work in other languages because Public Folders and All Public Folders are named in 'foreign' | ||
| Date: 24-Jan-2006 23:29 | ||
| Code level: intermediate | ||
| Code area: Outlook Form Design | ||
| Posted by: Simon Breeze | ||
| Body: |
||
| All 51comments |
| Page [ 1 2 3 4 5 6 Next >> ] | ||
|
|
Sue Mosher
25-Jan-2006 16:47
Very cool! I've been meaning to do a non-localized version for a while. THanks for beating me to it! |
|
|
|
Aaron Kogan
13-Feb-2006 02:14
Sue, this site has been very helpful. thanks for maintaining it and answering questions. i am trying to add an appointment to a public calendar (from Access) and having some problems. could you confirm that the following code is the proper use of the GetFolder function to make this work. fyi: i am testing it on w/ Office XP but the client is using Office 2003. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'begin code Dim golApp As Outlook.Application Dim fldFolder As MAPIFolder Dim strPublicFolder As String Dim obj As AppointmentItem Set golApp = New Outlook.Application strPublicFolder = "\Public Folders\All Public Folders\South Campus\Request Calendar" Set fldFolder = GetFolder(strPublicFolder) Set obj = fldFolder.Items.Add(olAppointmentItem) With obj .Start = Now() .Subject = "Test Appointment" .Location = "Cafeteria" .Save End With 'end code '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
|
|
Simon Breeze
13-Feb-2006 04:12
Aaron If you are using my GetPublicFolder you need to change two lines strPublicFolder = "South Campus\Request Calendar" Set fldFolder = GetPublicFolder(strPublicFolder) If you are using Sue's original GetFolder you just need to get rid of the first \ in your path. |
|
|
|
Aaron Kogan
13-Feb-2006 22:10
Simon, i noticed 2 things about your code. 1. the line 'Set objApp = Nothing' is releasing a variable that was NOT declared/used. i just commented it out. 2. the line ' Set objFolder = Application.Session.GetDefaultFolder(18)' needed to be changed to ' Set objFolder = Outlook.Application.Session.GetDefaultFolder(18)' in order to compile. was i correct in doing these? i am waiting for the results from the test to see if this all works. again, thanks for the help |
|
|
|
Simon Breeze
14-Feb-2006 05:56
Aaron. Both your points relate to the same thing. This is VBScript but I wrote it in VBA and converted it. I believe you are using it in VBA 1. Yes That line should have been removed when I converted it. Infact I must have removed it in my live code because I use option Explicit. Well Spotted. 2. Well, that should only be an issue in VBA. In VBScript on a form the Application object is always available. I deleted my VBA version but to use it in VBA you should 1. make all the declarations specific 2. use Outlook.Application - Set objAp = CreateObject("Outlook.Application") Set objFolder = objAp.Session.GetDefaultFolder(18) is the normal way. |
|
|
|
Sue Mosher
17-Feb-2006 15:41
Application is an intrinsic object in Outlook VBA, as well as in VBScript behind a custom Outlook form. |
|
|
|
Aaron Kogan
27-Feb-2006 21:05
in the TestOutlook(), when i try to save the appointment, the .Save method returns a Run Time Error: The Operation Failed. here is all my code. the IntelliSense does show this as method of the object. Please help! i also noticed that the obj object is being set to "" at run time; not sure if that is signficant. and yes, i am using VBA. GetPublicFolder(strFolderPath) Dim strMsg As String Dim colFolders Dim objFolder Dim arrFolders Dim i Dim objAp As Object strFolderPath = Replace(strFolderPath, "/", "\") arrFolders = Split(strFolderPath, "\") Set objAp = CreateObject("Outlook.Application") Set objFolder = objAp.Session.GetDefaultFolder(18) Set objFolder = objFolder.Folders.Item(arrFolders(0)) If Not objFolder Is Nothing Then For i = 1 To UBound(arrFolders) Set colFolders = objFolder.Folders Set objFolder = Nothing Set objFolder = colFolders.Item(arrFolders(i)) If objFolder Is Nothing Then Exit For End If Next End If End Function Public Function TestOutlook() Dim golApp As Outlook.Application Dim fldFolder As MAPIFolder Dim strPublicFolder As String Dim obj As Outlook.AppointmentItem Set golApp = New Outlook.Application strPublicFolder = "Pukalani Campus\FUR Calendar" Set fldFolder = GetPublicFolder(strPublicFolder) Set obj = fldFolder.Items.Add(olAppointmentItem) With obj .Start = Now() .Subject = "Test Appointment" .Location = "Cafeteria" .Save End With End Function |
|
|
|
Simon Breeze
28-Feb-2006 03:52
Why use two different methods of getting the application object? Each one is about half way right and Sue says that the application object is available in VBA anyway (unless of course your code is not in Outlook). If you need to instanciate an outlook application object here is how. Dim objApp as Outlook.Application Set objApp = CreateObject("Outlook.Application") I cant see anything specifically wrong with your .Save line. Is it possible you do not have the rights to save in that folder or that folder does not accept appointment items? |
|
|
|
Aaron Kogan
28-Feb-2006 11:52
thanks for the response. this is VBA code in an Access db. honestly, the reason i am getting the application object twice is i don't know what i am doing. i am really comfortable coding in Access and NOT very comfortable coding from Access to Outlook. if understand correctly, i do NOT need the Outlook golApp object variable in the TestOutlook() function because it is created in the GetPublicFolder(). is that correct? i thought about the permissions issue w/ the calendar as well but the person logged into the computer manually maintains this public calendar on a regular basis. i will research this more. again, thanks for the resonse. |
|
|
|
Simon Breeze
01-Mar-2006 04:07
Not quite. You have a choice. Either decalare it wice or declare it at module level (outside of the subs) Either way declare it as Outlook.Application and instanciate it with Set objOutlook = CreateObject("Outlook.Application") You must do the latter in each procedure if you are declaring the object in each. You may decide that if you are using it in a lot of procedures it is best to declare at module level and just instanciate the once. As a first thing to do I suggest you use the 2 lines I gave you before in each procedure you use the outlook Application object in. |
|
| Page [ 1 2 3 4 5 6 Next >> ] | ||
| Post your comment name email |
