H
Helix
Anyone know how I can delete the entire contents of a specific folder with
the press of a button.
Thanks,
Helix
the press of a button.
Thanks,
Helix
Eric Legault said:There's a great article at
http://support.microsoft.com/default.aspx?scid=kb;[LN];208520 that
illustrates how to get access to non-default folders.
Essentially, when you create a NameSpace object (Set
myNameSpaceVariableObject = Application.GetNameSpace("MAPI"), there is a
myNameSpaceVariableObject .Folders collection. This collection contains all
of your loaded .pst files (ie. Local Folders, Personal Folders, Archive
Folders, etc.). You can set a MAPIFolder object variable to a folder in
that collection by name:
Set myMAPIFolderObjectVariable = myNameSpaceVariableObject.Folders("Local
Folders").
Then all of the top-level subfolders for that .pst file (Inbox, Calendar,
Contacts, etc.) are in the myMAPIFolderObjectVariable.Folders collection.
The same thing goes to get one of those folders:
Set mybinboxFolder = myMAPIFolderObjectVariable.Folders("binbox").
mybinboxFolder.Items contains the messages in binbox, and
mybinboxFolder.Folders contains any subfolders in binbox.
Does this help?
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
Helix said:Eric,
The good news is that I created the macro "delete contents of folder" and
assigned it to a button and it worked beautifully. Now for selecting the
folder - "binbox" is not a default folder. It is one of eight folders that
I created under "Local Folders". I assume that the new code you suggested
goes in front of the "delete contents..." code. I am afraid I don't know
how to traverse the Folders collection from the NameSpace object.
Thanks,
Helix
this contents
of
Helix said:Below is what I came up with. Kindly supress all laughter. The debugger
hiccuped on this:
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Sub DeleteBinbox()
Dim myNameSpace As Outlook.NameSpace
Dim myMAPIFolder As Outlook.MAPIFolder
Dim mybinboxFolder As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder, objItems As Outlook.Items
Dim lngX As Long
Set myNameSpaceVariableObject = Application.GetNamespace("MAPI")
Set myMAPIFolderObjectVariable =
myNameSpaceVariableObject.Folders("Local Folders").
Set mybinboxFolder = myMAPIFolderObjectVariable.Folders("binbox").
Set objFolder = Application.ActiveExplorer.mybinboxFolder
Set objItems = objFolder.Items
For lngX = objItems.Count To 1 Step -1
objItems.Item(lngX).Delete
Next
End Sub
````````````````````````````````````````````````````````````````````````````
``````````````````````````````````````````````````
Eric Legault said:There's a great article at
http://support.microsoft.com/default.aspx?scid=kb;[LN];208520 that
illustrates how to get access to non-default folders.
Essentially, when you create a NameSpace object (Set
myNameSpaceVariableObject = Application.GetNameSpace("MAPI"), there is a
myNameSpaceVariableObject .Folders collection. This collection contains all
of your loaded .pst files (ie. Local Folders, Personal Folders, Archive
Folders, etc.). You can set a MAPIFolder object variable to a folder in
that collection by name:
Set myMAPIFolderObjectVariable = myNameSpaceVariableObject.Folders("Local
Folders").
Then all of the top-level subfolders for that .pst file (Inbox, Calendar,
Contacts, etc.) are in the myMAPIFolderObjectVariable.Folders collection.
The same thing goes to get one of those folders:
Set mybinboxFolder = myMAPIFolderObjectVariable.Folders("binbox").
mybinboxFolder.Items contains the messages in binbox, and
mybinboxFolder.Folders contains any subfolders in binbox.
Does this help?
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
foldersHelix said:Eric,
The good news is that I created the macro "delete contents of folder" and
assigned it to a button and it worked beautifully. Now for selecting the
folder - "binbox" is not a default folder. It is one of eight
thattraverseI created under "Local Folders". I assume that the new code you suggested
goes in front of the "delete contents..." code. I am afraid I don't know
how to traverse the Folders collection from the NameSpace object.
Thanks,
Helix
message This is how you retrieve your inbox:
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderInbox)
If you don't want one of the default folders, you'll have to
theFolders collection from the NameSpace object to get the folder you need.
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
Eric,
Since I will always be deleting from the same folder "binbox" can this
be
encoded in the macro. This would save having to select the folder or
perhaps deleting the contents of the wrong folder?
Helix
message Attach this macro to a custom button, which will delete the contents
of
the
current folder:
Sub DeleteAllMesssagesInCurrentFolder()
Dim objFolder As Outlook.MAPIFolder, objItems As Outlook.Items
Dim lngX As Long
Set objFolder = Application.ActiveExplorer.CurrentFolder
Set objItems = objFolder.Items
For lngX = objItems.Count To 1 Step -1
objItems.Item(lngX).Delete
Next
End Sub
--
Eric Legault, B.A., MCP, MCSD, MVP - Outlook
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault
Anyone know how I can delete the entire contents of a specific
folder
with
the press of a button.
Thanks,
Helix
Eric Legault said:Your variables are declared incorrectly:
Sub DeleteBinbox()
Dim myNameSpace As Outlook.NameSpace
Dim myMAPIFolder As Outlook.MAPIFolder
Dim mybinboxFolder As Outlook.MAPIFolder
Dim objItems As Outlook.Items
Dim lngX As Long
Set myNameSpace = Application.GetNamespace("MAPI")
Set myMAPIFolder = myNameSpace.Folders("Local Folders")
Set mybinboxFolder = myMAPIFolder.Folders("binbox")
Set objItems = mybinboxFolder.Items
For lngX = objItems.Count To 1 Step -1
objItems.Item(lngX).Delete
Next
End Sub
Make sure to set a breakpoints at 'Set myMAPIFolder' to make sure you get
the proper .pst, and one at 'Set mybinboxFolder' to make sure this is the
correct folder that has the messages you want to delete. Backup first
maybe!
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````Helix said:Below is what I came up with. Kindly supress all laughter. The debugger
hiccuped on this:````````````````````````````````````````````````````````````````````````````Sub DeleteBinbox()
Dim myNameSpace As Outlook.NameSpace
Dim myMAPIFolder As Outlook.MAPIFolder
Dim mybinboxFolder As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder, objItems As Outlook.Items
Dim lngX As Long
Set myNameSpaceVariableObject = Application.GetNamespace("MAPI")
Set myMAPIFolderObjectVariable =
myNameSpaceVariableObject.Folders("Local Folders").
Set mybinboxFolder = myMAPIFolderObjectVariable.Folders("binbox").
Set objFolder = Application.ActiveExplorer.mybinboxFolder
Set objItems = objFolder.Items
For lngX = objItems.Count To 1 Step -1
objItems.Item(lngX).Delete
Next
End Sub``````````````````````````````````````````````````
containsEric Legault said:There's a great article at
http://support.microsoft.com/default.aspx?scid=kb;[LN];208520 that
illustrates how to get access to non-default folders.
Essentially, when you create a NameSpace object (Set
myNameSpaceVariableObject = Application.GetNameSpace("MAPI"), there is a
myNameSpaceVariableObject .Folders collection. This collection
allfolder"of your loaded .pst files (ie. Local Folders, Personal Folders, Archive
Folders, etc.). You can set a MAPIFolder object variable to a folder in
that collection by name:
Set myMAPIFolderObjectVariable = myNameSpaceVariableObject.Folders("Local
Folders").
Then all of the top-level subfolders for that .pst file (Inbox, Calendar,
Contacts, etc.) are in the myMAPIFolderObjectVariable.Folders collection.
The same thing goes to get one of those folders:
Set mybinboxFolder = myMAPIFolderObjectVariable.Folders("binbox").
mybinboxFolder.Items contains the messages in binbox, and
mybinboxFolder.Folders contains any subfolders in binbox.
Does this help?
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
Eric,
The good news is that I created the macro "delete contents of
andselectingassigned it to a button and it worked beautifully. Now for
thefolderfolder - "binbox" is not a default folder. It is one of eight folders
that
I created under "Local Folders". I assume that the new code you suggested
goes in front of the "delete contents..." code. I am afraid I don't know
how to traverse the Folders collection from the NameSpace object.
Thanks,
Helix
message This is how you retrieve your inbox:
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderInbox)
If you don't want one of the default folders, you'll have to traverse
the
Folders collection from the NameSpace object to get the folder you need.
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
Eric,
Since I will always be deleting from the same folder "binbox" can
this
be
encoded in the macro. This would save having to select the
orwroteperhaps deleting the contents of the wrong folder?
Helix
"Eric Legault [Outlook MVP]" <[email protected]>
inmessage Attach this macro to a custom button, which will delete the contents
of
the
current folder:
Sub DeleteAllMesssagesInCurrentFolder()
Dim objFolder As Outlook.MAPIFolder, objItems As Outlook.Items
Dim lngX As Long
Set objFolder = Application.ActiveExplorer.CurrentFolder
Set objItems = objFolder.Items
For lngX = objItems.Count To 1 Step -1
objItems.Item(lngX).Delete
Next
End Sub
--
Eric Legault, B.A., MCP, MCSD, MVP - Outlook
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault
Anyone know how I can delete the entire contents of a specific
folder
with
the press of a button.
Thanks,
Helix
Helix said:Eric,
It works like a charm. I changed local folders to personal folders. This
will make it easy to empty the junk mail folder which fills up rapidly.
Thanks much,
Helix
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````Eric Legault said:Your variables are declared incorrectly:
Sub DeleteBinbox()
Dim myNameSpace As Outlook.NameSpace
Dim myMAPIFolder As Outlook.MAPIFolder
Dim mybinboxFolder As Outlook.MAPIFolder
Dim objItems As Outlook.Items
Dim lngX As Long
Set myNameSpace = Application.GetNamespace("MAPI")
Set myMAPIFolder = myNameSpace.Folders("Local Folders")
Set mybinboxFolder = myMAPIFolder.Folders("binbox")
Set objItems = mybinboxFolder.Items
For lngX = objItems.Count To 1 Step -1
objItems.Item(lngX).Delete
Next
End Sub
Make sure to set a breakpoints at 'Set myMAPIFolder' to make sure you get
the proper .pst, and one at 'Set mybinboxFolder' to make sure this is the
correct folder that has the messages you want to delete. Backup first
maybe!is``````````````````````````````````````````````````
message There's a great article at
http://support.microsoft.com/default.aspx?scid=kb;[LN];208520 that
illustrates how to get access to non-default folders.
Essentially, when you create a NameSpace object (Set
myNameSpaceVariableObject = Application.GetNameSpace("MAPI"), therefolderinwrotethat collection by name:
Set myMAPIFolderObjectVariable = myNameSpaceVariableObject.Folders("Local
Folders").
Then all of the top-level subfolders for that .pst file (Inbox, Calendar,
Contacts, etc.) are in the myMAPIFolderObjectVariable.Folders collection.
The same thing goes to get one of those folders:
Set mybinboxFolder = myMAPIFolderObjectVariable.Folders("binbox").
mybinboxFolder.Items contains the messages in binbox, and
mybinboxFolder.Folders contains any subfolders in binbox.
Does this help?
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
Eric,
The good news is that I created the macro "delete contents of folder"
and
assigned it to a button and it worked beautifully. Now for selecting
the
folder - "binbox" is not a default folder. It is one of eight folders
that
I created under "Local Folders". I assume that the new code you
suggested
goes in front of the "delete contents..." code. I am afraid I don't
know
how to traverse the Folders collection from the NameSpace object.
Thanks,
Helix
"Eric Legault [MVP - Outlook]" <[email protected]>
inmessage This is how you retrieve your inbox:
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderInbox)
If you don't want one of the default folders, you'll have to traverse
the
Folders collection from the NameSpace object to get the folder you
need.
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
Eric,
Since I will always be deleting from the same folder "binbox" can
this
be
encoded in the macro. This would save having to select the folder
or
perhaps deleting the contents of the wrong folder?
Helix
in
message Attach this macro to a custom button, which will delete the
contents
of
the
current folder:
Sub DeleteAllMesssagesInCurrentFolder()
Dim objFolder As Outlook.MAPIFolder, objItems As Outlook.Items
Dim lngX As Long
Set objFolder = Application.ActiveExplorer.CurrentFolder
Set objItems = objFolder.Items
For lngX = objItems.Count To 1 Step -1
objItems.Item(lngX).Delete
Next
End Sub
--
Eric Legault, B.A., MCP, MCSD, MVP - Outlook
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault
Anyone know how I can delete the entire contents of a specific
folder
with
the press of a button.
Thanks,
Helix