how to get Outlook VBA code to work on the current folder

Status
Not open for further replies.

revansx

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Hi. This is my first post here. please let me know if there is a more appropriate place to ask this:

I have the following VBA code (below) that works well for any mail in the "Inbox".

I execute it manually from the VBA ThisOutlookSession environment (Alt-F11)

But I also have lots of mail in folders from mapped PST files and what I want to do is make this code so that it works on whatever the "currently selected" folder is; even if it is a sub-folder in a PST file.

Is that possible?

Here is the code:

----------------Private Sub SetInitialProperties()
Dim ns As Outlook.NameSpace
Dim fld As Outlook.MAPIFolder
Dim objUnknown As Object
Dim mail As Outlook.MailItem
Dim prop As Outlook.UserProperty
Set ns = Application.GetNamespace("MAPI")
Set fld = ns.GetDefaultFolder(olFolderInbox)

For Each objUnknown In fld.Items
If TypeOf objUnknown Is MailItem Then
... do stuff ...
End If
Next

Set objUnknown = Nothing
Set fld = Nothing
Set ns = Nothing

End Sub

--------------------Thanks!

-Rich
 

revansx

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I'm also looking at this post (below) as my primary approach to accessing folders that are not sub-folders of the Inbox

http://blogs.technet.com/b/heyscrip...at-isn-t-a-subfolder-of-my-outlook-inbox.aspx

so I think I have the clues I need to reference a folder in a mapped PST file... but this isn't the same as having VBA "fetch" the current folder the user is looking at.

That's what I'm curious about if it's possible.

Continued Thanks!
 

revansx

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Diane,

Holy Cow! That worked perfectly! and was so simple... how is that possible :p

But really, Diane, thank you so much. You made my day. :cool:

Cheers!

-Rich
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
M VBA Code to Restart Outlook on error Outlook VBA and Custom Forms 3
Z Default VBA code for extracting data from email (Outlook) to Excel? Outlook VBA and Custom Forms 1
M VBA Auto-Reply code for Two Mailboxes on one Outlook Session. Outlook VBA and Custom Forms 4
Kelli VBA code for Outlook Using Outlook 1
M VBA Code to extract data from an Outlook Form Using Outlook 0
M VBA code needed to move from Outlook 2010 subfolder to Symantec Vault subfolde Using Outlook 0
C In need of VBA code to read / parse HTML - Outlook emails Using Outlook 0
R [VBA] complicated(?) outlook events - need help with code Using Outlook 15
J VBA code can't be completely executed in outlook 2013 Using Outlook 0
P VBA Code being completely ignored by Outlook Using Outlook 7
M Updating VBA code from outlook 2007 to outlook 2010 Using Outlook 1
A Accessing .pst folder in outlook using VBA Code Outlook VBA and Custom Forms 4
P 'Trusted' VBA code in Outlook 2003? Outlook VBA and Custom Forms 2
J Want to learn VBA Macros for Outlook. What book can you recommend? Outlook VBA and Custom Forms 2
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
G Outlook VBA and Google Calendar ("Events") Outlook VBA and Custom Forms 1
J VBA Outlook : Subject line : Cut and Paste name to heading , number to very end of the body of Email Outlook VBA and Custom Forms 1
B Advanced Search in MS Outlook by VBA and SQL Outlook VBA and Custom Forms 2
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
S Find a cell value in excel using outlook vba Using Outlook 1
J Execute Add-In Button from VBA Outlook 2016 Outlook VBA and Custom Forms 1
J Open an outlook email by Subject on MS Access linked table with VBA Outlook VBA and Custom Forms 10
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5
T Outlook AntiSpam with VBA Outlook VBA and Custom Forms 1
F "Move to" O365 feature to Outlook client via VBA Outlook VBA and Custom Forms 4
B query outlook using vba Outlook VBA and Custom Forms 13
J VBA to switch Outlook online/offline Outlook VBA and Custom Forms 4
M VBA to change flag status in outlook contact item Outlook VBA and Custom Forms 3
T VBA outlook, detect priority emails Outlook VBA and Custom Forms 5
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
S Outlook VBA Contacts Notes Outlook VBA and Custom Forms 0
O VBA to Run Font Change on Outlook Startup Outlook VBA and Custom Forms 4
P Outlook 2007 Email Categorization using VBA Outlook VBA and Custom Forms 1
O VBA or other solution for Outlook tasks to OneNote Outlook VBA and Custom Forms 0
S Automatically selecting folders and deleting messages in Outlook VBA Outlook VBA and Custom Forms 7
D Creating an outlook session from Access vba but run silently. With A specific profile Outlook VBA and Custom Forms 1
Diane Poremsky Outlook VBA: Use a Text File to Populate a ListBox New Slipstick.com Articles 0
C Saving Outlook attachments and links to attachments with VBA Outlook VBA and Custom Forms 2
Diane Poremsky Outlook VBA: Work with Open Item or Selected Item New Slipstick.com Articles 0

Similar threads

Top