Open folder with vba code launches a new window


G

Guest

I have Outlook 2003. Basically I have an email in my inbox and when I run
this macro, I want the email to be moved to the folder "Problem
Report\Laptop" and then open this folder. My code works fine, but it's the
last line
(e.g. objFolder.Display) that I don't like. I want to open the folder, but
not launch a new window. If I manually open different folders, new windows
don't open so I'm hoping to do the same with code. I'm limited to what I
know with VBA so this was the only code I could at least get working.

Here is my code:

' Opens folder Problem Report\Laptop
Dim objOlApp As Outlook.Application
Dim objRecipient As Outlook.Recipient

Set objOlApp = CreateObject("Outlook.Application")
Set objNS = objOlApp.GetNamespace("MAPI")
Set objRecipient = objNS.CreateRecipient("Problem Report")

Set objFolder = GetFolder("Mailbox - Problem Report\Laptop")
objFolder.Display 'Will launch new window

Any assistance would be greatly appreciated.

Thanks!
 
Ad

Advertisements

S

Sue Mosher [MVP-Outlook]

Use this statement instead:

Set objOLApp.ActiveExplorer.CurrentFolder = objFolder

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Perfect! Thank you so much Sue.

LDMueller

Sue Mosher said:
Use this statement instead:

Set objOLApp.ActiveExplorer.CurrentFolder = objFolder

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Joined
Apr 20, 2014
Messages
2
Reaction score
0
In contrast to the person who started this thread, I would like to open several Outlook default folders - eg calendar, contacts etc - AND launch each in a new window. Every folder displays its own icon, making it easy to identify with ALT-TAB, if I open it manually, (right click, open in new window). However, each folder displays the same inbox icon, making it difficult to identify with ALT-TAB, if I open them programmatically in vba, using the following code:

+++++++
Sub openfolderwindows()

On Error Resume Next
Dim NS As Outlook.NameSpace
Dim Folders As Outlook.Folders
Dim F As Outlook.MAPIFolder
Dim ExpandDefaultStoreOnly As Boolean

'which folders should be opened?
'(false = all +/- conditions; true = personal folders only)
ExpandDefaultStoreOnly = True
Set NS = Application.GetNamespace("Mapi")

If ExpandDefaultStoreOnly = True Then
'open personal folders only
Set F = NS.GetDefaultFolder(olFolderInbox)
Set F = F.Parent
Set Folders = F.Folders
loopwindows Folders, True
Else
'open all folders
loopwindows NS.Folders, True
End If

DoEvents

End Sub
Sub loopwindows(Folders As Outlook.Folders, ByVal bRecursive As Boolean)

For Each F In Folders
Set Application.ActiveExplorer.CurrentFolder = F
If F = "Outbox" Or F = "Calendar" Or F = "Contacts" Or F = "Tasks" Then
F.Display
DoEvents
If bRecursive Then
If F.Folders.count Then
loopwindows F.Folders, bRecursive
End If
End If
End If
Next

End Sub

+++++++

Although the same folders that were open in the last session should appear when restarting Outlook, the program crashes too often to rely on this. I've also seen information about setting a custom icon for Outlook folders; but not all accept custom icons - in particular the default folders.

I'm using Outlook 2010 at present but just about to upgrade to 2013. Can anyone help?
 
Joined
Jun 6, 2014
Messages
11
Reaction score
0
This should work for you. Outlook.Application.ActiveExplorer.CurrentFolder = FolderName.
 
Ad

Advertisements

Joined
Apr 20, 2014
Messages
2
Reaction score
0
Many thanks. However, where are you suggesting that this line of code be added within my routine?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top