OL2007 - is there a way to disable the "feature" that cripples mails that are in the "junk" folder?

Status
Not open for further replies.

zdoe

Member
see - i don't want to always have to move the mails elsewhere to scan them, and viewing the messed-up mails there is just not an option. i'm on whitelist-only to the inbox, so i do have to scan spam periodically.

if that folder could be fixed, that would be best/simplest.

if not, i'd be happy with an automated thingy that would move things elsewhere as soon as they arrive, but i've not been able to write a rule that would do this easily and user-controllably - basically because the whitelist is not easily user-manageable.

i used to do this with spampal and NOT using outlook's spam (dys)functionality. but spampal is at retirement age and quite resource-hungry, so i dropped it a while back after some other app had messed with its transparent proxying and i would've had to spend some time on it.

now - i'm already running a VBA macro at system startup to get the doubled-line-feeds -problem sorted, so was wondering if someone smarter than me would be able to write a simple piece of VBA code that would move anything from junk folder to a user-designated real folder?

thoughts?
 
Why not just disable the junk mail feature?
i do need machine-assisted pre-sorting - otherwise it becomes too laborious to manage the junk.

However, you could use an item add macro to watch the folder and move all mail that hits it.
item add macro - yes, i believe that would be the answer. where could i find a resource on how to do it? or - if it's just a few lines of code, could you perhaps please provide those?
 
I might have one around here somewhere - see the last macro here - http://www.slipstick.com/outlook/rules/mark-items-read/ - you'll need to use this line in the startup macro:
Set Items = Session.GetDefaultFolder(olFolderjunk).Items

and something like this in the item add macro, assuming the folder is at the same level as the inbox and is called My Stuff. :)

Set Items = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("My Stuff")

More info on using non-default folders is here: http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/
 
finally collected the courage to try this out - i'm a nooooob! have copy pasted your suggested code and renamed folders wo what i think they are on my box.

(and i finally got my first "hello world" macro lifted from the net to run... - so not all is hopless)

i get a compile error, that points to the line 2, with the code:
Private WithEvents Items As Outlook.Items

Sub JunkToZunk()
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Set Items = Session.GetDefaultFolder(olFolderJunk).Items
' Set Items = Session.GetDefaultFolder(olFolderSentMail).Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Set Items = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("xPort")
' Set MovePst = GetFolderPath("NewPST\Sent Items")
Set MovePst = GetFolderPath("\xPort\Zunk")
Item.UnRead = False
Item.Move MovePst
End Sub

what might i have done wrong?
 
at the very least, the lines are in the wrong order -

The Application_Startup macro tells outlook to watch the junk mail folder. Because you are using a folder in your mailbox, you don't need to use GetFolderPath. If xPort is at the same level as the Inbox, this code should work.

Code:
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Set Items = Session.GetDefaultFolder(olFolderJunk).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
Set MovePst = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("xPort")
Item.UnRead = False
Item.Move MovePst
End Sub
 
tried - doesn't seem to do anything, but now i don't now get a compile-error.

should the code be in:
Module; or
ClassModule; or
Application

& also:

the target folder is on the top level of a pst - shouldn't it be pointing to that pst - e.g. - \xPort\Zunk

again apologies for my noobiness - this is the first time i'm trying to do something with VBA.
 
it needs to be in ThisOutlookSession, private withevents and application_startup belong at the top.

is xPort a pst or a folder within a data file?

The code in my sample assumes it's a folder in the folder tree like this:
zdoe@example.com
-Inbox
-Calendar
-contacts
-Deleted Items
-xPort


If it's a separate pst, and xPort is the display name in the folder list, then you need to use
Set MovePst = GetFolderPath("xPort\Zunk") and get the GetFolderPath function.

zdoe@example.com
-Inbox
-Calendar
-contacts
-Deleted Items

xPort
- More
-Zunk
-Deleted Items
 
it needs to be in ThisOutlookSession, private withevents and application_startup belong at the top.

is xPort a pst or a folder within a data file? If it's a separate pst, and xPort is the display name in the folder list, then you need to use

Set MovePst = GetFolderPath("xPort\Zunk") and get the GetFolderPath function.

zdoe@example.com
-Inbox
-Calendar
-contacts
-Deleted Items

xPort
- More
-Zunk
-Deleted Items
yes, it's a separate PST called xPort on the OL folder tree. so below is what i got now - seemingly still not running.

OLmacroCode.jpg
 
i did NOT have GetFolderPath on the last go. now i do, as below.

if i put it in the top of the page i get a compile error. in the bottom or in a separate module no compile errors. but the VBA is seemingly still not doing anything.

-------------------ThisOutlookSession:

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Set Items = Session.GetDefaultFolder(olFolderJunk).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
' Set MovePst = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("\xPort\Zunk")
Set MovePst = GetFolderPath("\xPort\Zunk")
Item.UnRead = False
Item.Move MovePst
End Sub

Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer

On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function

GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function
 
Did you restart outlook or click in the application startup macro and click Run? Is macro security set to low?
 
security = no macro security
nothing appears on the macro list - for this code, or otherwise. when i was testing "hello world" it was on the macro list.
 
Private subs aren't listed under macros - neither are ones that are triggered automatically. This is an application startup that watches for new messages to land in a folder so they won't be listed.

This: \xPort\Zunk should be: xPort\Zunk
 
i suspected that about start-up macros...

fixed xPort\Zunk /restarted outlook - still no jive:

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Set Items = Session.GetDefaultFolder(olFolderJunk).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
' Set MovePst = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("xPort\Zunk")
Set MovePst = GetFolderPath("xPort\Zunk")
Item.UnRead = False
Item.Move MovePst
End Sub

Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer

On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function

GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function
 
Add this to the bottom of the thisoutlooksession and select a message and click run. does it move the message?

Code:
Public Sub ManualTest()
    Dim objMail As Object
    Set objMail = Application.ActiveExplorer.Selection.Item(1)
    Items_ItemAdd objMail
Set objMail = Nothing
End Sub

Another options is to add the following as the first line in the itemadd macro. Every time it gets called, it will run. You can add it to the startup macro too.
msgbox "Macro is working"

Are any of the lines red? blue, green, and black are good. Red bad. :)
 
no red lines - other colors prevail. ;-)

the new code moves the selected message, indeed. so it seems that for some reason the code doesn't run on startup, or fails to detect new mails that landed in the junk folder. the "itemadd is running" message box pops up as well, requiring a click.

another curious thing is that when i'm resuming from sleep or switching displays i get a full screen view of the VBA editor even if i didn't start it for a while.
-------------
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Set Items = Session.GetDefaultFolder(olFolderJunk).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
' Set MovePst = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("xPort\Zunk")
MsgBox "ItemAdd is running"
Set MovePst = GetFolderPath("xPort\Zunk")
Item.UnRead = False
Item.Move MovePst
End Sub

Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer

On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function

GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function

Public Sub ManualTest()
Dim objMail As Object
Set objMail = Application.ActiveExplorer.Selection.Item(1)
Items_ItemAdd objMail
Set objMail = Nothing
End Sub
 
another curious thing is that when i'm resuming from sleep or switching displays i get a full screen view of the VBA editor even if i didn't start it for a while.
This is a bug - I haven't figured out why it does it, but i see it occasionally.

I'll test the code tomorrow morning and see if i can figure out why it's failing for you.
 
one question - is the junk folder we're watching in the default data file?

Actually, another way to test it: move mail into the junk mail folder or select mail that is there and copy and paste... that way you can test the item add part.

I probably should have recorded this using Outlook 2007 (it works in all newer versions) but i quickly glanced at the thread and didn't see you mention the version - I noticed the subject after I had it posted on youtube (and didn't want to redo it).

 
wow ! a video ! thank you.

Junk folder IS in the default data file - courtesy Bill Gates.

and my folders are as you'd (re)created them - listed at the tail of this.

so - as mentioned before, AddItem does move the email that's selected to the right target folder. but the other macro/subroutine either fails to start on startup, or fails to notice the incoming mails - this whether mail-in-question is copied to Junk E-mail or copy / pasted within it.

list of folders by some VBS utility - notable, perhaps, that "Junk E-mail" doesn't appear on the list.
1/26/2015 1:40:55 AM: Selected Archive Name: Inbox
1/26/2015 1:40:55 AM: Total Number of Sub Folders: 0
1/26/2015 1:41:16 AM: Selected Archive Name: xPort
1/26/2015 2:01:16 AM: Total Number of Sub Folders: 5
1/26/2015 2:01:16 AM: \\xPort\Deleted Items
1/26/2015 2:01:16 AM: \\xPort\Zunk
1/26/2015 2:01:16 AM: \\xPort\xContacts
1/26/2015 2:01:16 AM: \\xPort\SiteStats
1/26/2015 2:01:16 AM: \\xPort\Dr-N Notifications
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Does the .fdm contain my custom form? How to make ol use it? - ol2007 Outlook VBA and Custom Forms 4
E OL2007 on Exchange: opening OL on different computers Using Outlook 1
R Multiple instances of OL2007 and creating rules Exchange Server Administration 1
P OL2007 -- All day appt. end time is "tomorrow" Using Outlook 3
T Search for multiple contacts in OL2007 Using Outlook 3
M Develop for OL2003 on OL2007 machine using VS2008 and VSTO? Outlook VBA and Custom Forms 1
M OL2007 Add-in won't install on OL2010 Outlook VBA and Custom Forms 1
P Embed Word doc w/form into OL2007 form Outlook VBA and Custom Forms 1
N Right-click an address -> add to BCM? [OL2007] BCM (Business Contact Manager) 1
J Deploying OL2007 Add-In Outlook VBA and Custom Forms 3
A How to replace getcontactsfolder (ol2007) in Outlook 2003 Outlook VBA and Custom Forms 2
P Redemption not working on OL2007 Outlook VBA and Custom Forms 2
J disable Alt+S shortcut Using Outlook 21
J Hide/disable "Groups", "Shared Calendars" Using Outlook 2
G To enable/disable Allow New Time proposals Outlook VBA and Custom Forms 1
Y Disable Microsoft Outlook Test Message Using Outlook 4
J How do you disable address search box when typing @ in body of email? Using Outlook 0
L Is there a way to completely disable the "archive" box? Using Outlook 1
M Disable Contact Card Results when using "Search People" in Outlook Ribbon Using Outlook 7
U Disable "Always ask before opening" Dialog Using Outlook 3
J How do I disable advertising in Outlook 2019? Using Outlook 15
GregS Outlook 2016 Can I disable the Outlook Outbox? Using Outlook 2
R Disable conversation thread from replying of recipients in the same subject. Please help Using Outlook 0
N Disable Auto Read Receipts sent after using Advanced Find Using Outlook 4
N How to disable shortcuts for Pilcrow in Outlook (Show or hide paragraph marks) Using Outlook 0
N How to disable shortcuts for Pilcrow in Outlook Using Outlook 0
M Making Subject field writable (disable Read Only) Outlook VBA and Custom Forms 2
D Disable or hide "reply" and "reply to all" and "forward" in email from access vba Outlook VBA and Custom Forms 1
P Disable Spam Notifications & Sounds Using Outlook 3
O Outlook Web Access - how to disable spam filter Using Outlook 6
Diane Poremsky Disable Protected View for Outlook Attachments Using Outlook 0
E Outlook 2010 disable date auto-complete Using Outlook 2
Diane Poremsky Disable Outlook Add-ins (Apps) Using Outlook 0
J Using VBA to disable alerts / warnings Using Outlook 2
Diane Poremsky Disable the Unsafe Hyperlink Warning when Opening Attachments Using Outlook 0
N How to disable user defined fields in BCM forms Using Outlook 2
Diane Poremsky Disable Live Preview in Outlook and Word Using Outlook 0
D Preventing users to disable an Outlook Add-in Using Outlook.com accounts in Outlook 5
F Disable "Find related messages" Using Outlook 1
davecazz Anyway to disable the peek rollovers? Using Outlook 1
L Reading Pane - COMPLETELY DISABLE? Using Outlook 10
M trying to disable junk email filter. completely. Using Outlook 4
B How do I REALLY disable Outlook Junk E-mail sorting in OL2010 and/or 2013? Using Outlook 1
R Outlook Cache Mode Terminalserver disable through Registry Using Outlook 1
S Cannot disable OWA light Exchange Server Administration 5
A How to disable the pop-up “Reponses to this meeting will not be tallied." Using Outlook 0
D Show this folder as an e-mail Address Book is enabled but I want to disable Using Outlook 2
Rupert Dragwater how to disable billingual dictionary in outlook 2010 Using Outlook 9
J How to disable syncing folder views/layouts Using Outlook 5
A Disable hotmail from Outlook email account Using Outlook 1

Similar threads

Back
Top