PDA

View Full Version : button shortcut to display public folder



WallIT
04-15-2014, 03:35 AM
Hi,

I have a basic understanding of Outlook VBA, but what I want to achieve is, as I understand, fairly simple.

I would like to create a button which when pressed shows a particular Public Folder. I have some code that allows me to find and return a unique ID for a given public folder, which is the first part solved. I also have some code which shows the correct folder. The code is...


Private Sub GetFolderFromID()
Dim olfolder As Outlook.MAPIFolder
Dim olapp As Outlook.Application
Set olapp = CreateObject("Outlook.Application")
Set olfolder = olapp.GetNamespace("Mapi").GetFolderFromID("InsertEntryIDHere")
olfolder.Display
Set olfolder = Nothing
Set olapp = Nothing
End Sub

The only problem with this code is it opens a new and separate Outlook application session, where I would prefer it to open in the current session. How can I tweak my code to show in the current session instead?

Many thanks

westconn1
04-15-2014, 01:53 PM
yes work with the application object, rather than creating a new one

change to
set olapp = applicaton

WallIT
04-16-2014, 01:44 AM
yes work with the application object, rather than creating a new one

change to
set olapp = applicaton

Thanks. I changed the line as you suggest, but I still get another outlook session opening. I have looked at other similar code, which uses the line...

Application.ActiveExplorer.CurrentFolder =

...which looks like it might do the job I want. Could this be used somewhere?

WallIT
04-28-2014, 07:21 AM
Can anyone else help with this? On top of the problem about opening a new session, I'm also having problems making a working 'button' out of this. I have customised my toolbar, which I am familiar with. I have added a button and assigned it to the macro for opening the public folder. However, when you close and open Outlook fresh, the button doesn't work. You press it, but it does nothing. Only if I navigate manually and click on the public folder, then move away to another folder, does the button then start working. It'll continue working until I close and reopen Outlook. Weird!

skatonni
07-09-2014, 02:50 PM
Try Set myOlApp = GetObject(, "Outlook.Application")

To reference a Public Folder http://blogs.msdn.com/b/brijs/archive/2010/07/30/how-to-get-reference-to-public-folder-store-using-outlook-object-model-for-outlook-2010.aspx

WallIT
07-10-2014, 03:09 AM
Try Set myOlApp = GetObject(, "Outlook.Application")

To reference a Public Folder http://blogs.msdn.com/b/brijs/archive/2010/07/30/how-to-get-reference-to-public-folder-store-using-outlook-object-model-for-outlook-2010.aspx

Hi Skatonni,

Thanks for your reply. However, I'm not sure where to put your code. Does your code prevent Outlook opening another window? If you could give some guidance about where it goes, that would be greatly appreciated.

Thanks.

skatonni
07-11-2014, 10:15 AM
Replace CreateObject with GetObject

http://support.microsoft.com/kb/288902


Private Sub GetFolderFromID()
Dim olfolder As Outlook.MAPIFolder
Dim olapp As Outlook.Application

Set olapp = GetObject(, "Outlook.Application")

ReferencePublicFolders_2010

Set olfolder = olapp.GetNamespace("Mapi").GetFolderFromID("InsertEntryIDHere")

olfolder.Display

Set olfolder = Nothing
Set olapp = Nothing
End Sub

Sub ReferencePublicFolders_2010()
'
' Use exact name of top level Public Folder to reference in 2010
'
Dim olNS As Namespace
Dim pub As MAPIFolder
Set olNS = Application.GetNamespace("MAPI")
Set pub = olNS.Folders("Public Folders - name @ place.com")
Set olNS = Nothing
Set pub = Nothing
End Sub

WallIT
07-15-2014, 04:01 AM
Thanks again Skatonni.

I have copied and pasted your code but it still causes Outlook to open in a new window. I have assigned the macro to a custom toolbar button and I am launching it from there. Even if I execute the code from the VBA editor it still causes a separate Outlook window to open.

Bizarre.

skatonni
07-16-2014, 02:54 PM
I had not recreated the situation before. I have now. Try this code which sets the Current Folder instead.


Private Sub GetFolderFromID()
Dim olapp As Outlook.Application
Set olapp = CreateObject("Outlook.Application")
Set myolapp.ActiveExplorer.CurrentFolder = Application.GetNamespace("Mapi").GetFolderFromID("InsertEntryIDHere")
Set olapp = Nothing
End Sub

WallIT
07-17-2014, 02:01 AM
Thanks. When I try that I get error "object required" on the 4th line. I noticed "Set myolapp..." is not declared. Does it need to be?

westconn1
07-17-2014, 02:39 AM
it is a typo, drop the my

WallIT
07-17-2014, 03:45 AM
it is a typo, drop the my

Perfect. Thanks, this worked a charm! The public folder now opens in the existing Outlook session, rather than opening a new one.

Thanks to all that helped.