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
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