Outlook VBA

JimReid

New Member
Joined
Dec 13, 2017
Messages
2
Sorry, this isn't about Excel but don't where else to ask the question.

When you open outlook (windows) a folder (generally Inbox) has the focus. By focus, I mean it is the one that has a listing of the emails received. If you go to another folder (like Trash) and then run a macro (vba) the focus stays on that folder (in this example Trash). I would like to know how to force the focus back to the Inbox. My macro deletes (erases) all files in my Deleted folder and Trash folder. I would like it to come back to the Inbox when complete.

I am not talking about a 'Focused Inbox' but the highlighted folder. Maybe I should be saying to go back to highlight Inbox!?

It appears that when running a macro the highlighted folder stays as before the macro is run. I would like the vba code to set it back to Inbox.

Any help would be appreciated.

The following is my macro:

Public Sub EmptyFolder()
Dim Items As Outlook.Items
Dim i As Long
Dim Count As Long
Dim Delete As Boolean
' Clear Junk Items
Set ns = Application.GetNamespace("MAPI") Set Items = Session.GetDefaultFolder(olFolderCalendar).Parent.Folders("Junk").Items
Count = Items.Count
If Count = 0 Then
GoTo DeleteAll
End If
Delete = True
For i = Count To 1 Step -1
Items(i).Delete
Next
DeleteAll:
' Clear Trash Items
Set Items = Session.GetDefaultFolder(olFolderCalendar).Parent.Folders("Trash").Items
Count = Items.Count
If Count = 0 Then
GoTo EndAll
End If
Delete = True
For i = Count To 1 Step -1
Items(i).Delete
Next
EndAll:
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,671
Office Version
  1. 365
Platform
  1. Windows
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 

JimReid

New Member
Joined
Dec 13, 2017
Messages
2
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
I appreciate your concern over cross posting. In my case if I had added links for the cross postings it would possibly mislead people searching for answers because the only thing I got was someone trying to explain to what 'Focus' meant. I think cross posting would be if I used the exact same post in multiple places. In my case when I posted here it was a more detailed posting and with samples of the macro code and a more descriptive example of what I was trying to accomplish. My second point would be that when I couldn't get a decent response on other forums, I left those forums and didn't go back. I didn't remember where all I posted the problem, so I couldn't have links to them.

Generally speaking, when you have a problem you are trying to resolve you really don't want to get caught up in BS or semantics, your just looking for ideas or solutions and some people try to respond just to hear themselves talk and don't give any possible solutions. The example is the guy who tried to tell me I wanted a "Focused InBox" which is not what I was asking. Anyway, thanks for your help, and I'm sure I'll be back here more often than the others because of the civil responses.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,671
Office Version
  1. 365
Platform
  1. Windows
Cross posting is when you post the same question on multiple sites (which is what you have done) & therefore you need to let members here know, by supplying links to those other sites.
The fact that you did not get the help that you wanted is not the point. Please supply links to all other sites where you have asked this question as requested.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,800
Messages
5,638,427
Members
417,025
Latest member
MusterDuster

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top