InputBox for variable folder

Status
Not open for further replies.

Bamerand

Senior Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
I was able to locate a nice piece of code, can anyone help to modify it so that Set Folder = GetFolder("\\mymail@domain.com\Inbox\Training") I could place variable folder? For instance, I tried Set Folder = GetFolder.InputBox() but this function does not work in case! Please advise what can be done so that instead of constant folder I could go to variable folder.

Here is the code.

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

Sub TestGetFolder()
Dim Folder As Outlook.Folder
Set Folder = GetFolder("\\mymail@domain.com\Inbox\Training")
If Not (Folder Is Nothing) Then
Folder.Display
End If
End Sub
 

Bamerand

Senior Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
Yes, Diana, that is exactly what I need! How can I do that?
 

Bamerand

Senior Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
Dear Diana,

Thanks for the provided code, however, I think I misinterpreted on the requirement. See the included code and attached screenshot I took. When the code shoots off, MS Outlook activates Oracle subfolder, which is located under Inbox in my account. What I wish, instead of changing the destination folder in the line “\\mymail@domain.com\Inbox\Oracle”, a pop-up window, similar to InputBox pops up and I could put the full path of the email folder / subfolder, for instance, “\\mymail@domain.com\Sent\Invoices”. I hope this time I made it clear.
 

Attachments

  • Screenshot.png
    Screenshot.png
    26.4 KB · Views: 403

Bamerand

Senior Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
Sub TestGetFolder()
Dim Folder As Outlook.Folder
Set Folder = GetFolder("\\mymail@domain.com\Inbox\Inbox\Oracle")
If Not (Folder Is Nothing) Then
Folder.Display
End If
End Sub

I forgot to add the code.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Dear Diana,

Thanks for the provided code, however, I think I misinterpreted on the requirement. See the included code and attached screenshot I took. When the code shoots off, MS Outlook activates Oracle subfolder, which is located under Inbox in my account. What I wish, instead of changing the destination folder in the line “\\mymail@domain.com\Inbox\Oracle”, a pop-up window, similar to InputBox pops up and I could put the full path of the email folder / subfolder, for instance, “\\mymail@domain.com\Sent\Invoices”. I hope this time I made it clear.
so you just want to type the path in?

use the inputbox to set a variable then use the variable in the path -
Set Folder = GetFolder(myFolder)

if you want the mailbox name to be preselected and just the path entered, you can do that to - use "\\mymail@domain.com\" & myFolder

if you want to make this macro work for anyone's default mailbox, you can get their default mailbox path - or if it's always under the inbox, get their default inbox and set it as a variable too - so you'd use myMailbox & myFolder in the path. See Working with VBA and non-default Outlook Folders for examples.
 

Bamerand

Senior Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
Dear Diana,

Thanks, that was indeed helpful!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A How to assign the value returned by the regex execute function to a variable? Using Outlook 1
J Automatic color category according to variable domains Outlook VBA and Custom Forms 4
J Object Variable or With Block Not Set Error in Outlook 2016 and not Outlook 2013 Outlook VBA and Custom Forms 3
R Macro to copy email to excel - Runtime Error 91 Object Variable Not Set Outlook VBA and Custom Forms 11
D Outlook Rules - How to use a variable in the subject condition Outlook VBA and Custom Forms 9
M Modifying Macro MoveAgedMail(2) - use categories & "to" as variable Using Outlook 12
A Outlook VBA - moving mail item to public folder using variable within path Using Outlook 6
E Outlook could not create the work file. Check the temp environment variable Using Outlook 8
C Variable Attachments in CDO/OL2K7? Outlook VBA and Custom Forms 4
M VSTO C#: How do I declare an application scope variable? Outlook VBA and Custom Forms 2
S Folder Pane Colour Categories Using Outlook 1
Victor.Ayala Automated way to check the option "Show this folder as an email Address Book" Outlook VBA and Custom Forms 0
NVDon Create new Move To Folder list Outlook VBA and Custom Forms 0
M Extract "Date sent" from emails (saved to folder using drag and drop) Outlook VBA and Custom Forms 1
O Cannot expand the folder. The set of folders cannot be opened. You do not have permission to log on. Using Outlook 1
F Jump to Inbox folder when click on Favorite Using Outlook 8
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
lcarpay Stay in the mail folder pane after ctrl-1 Using Outlook 1
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 11
bhamberg Shortcuts in Folder Pane (Outlook 2016) Using Outlook 19
G VBA to save selected Outlook msg with new name in selected network Windows folder Outlook VBA and Custom Forms 1
P Posts in Folder No Longer Group by Conversation Column After Search Using Outlook 0
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
Horsepower Moving emails between folder Outlook for Mac Outlook Wishlist 8
N contact list seen in Contact folder but knot in Address book or when 'TO' button is clicked in new email Using Outlook 0
D How to remove a folder, option grayed out Using Outlook 4
D How To Combine Share Task Folders in just one Folder Using Outlook 0
G Retention Policy for Outlook.com Deleted Items folder Using Outlook 0
Z Outlook 365 delete reminder you can’t make change to contents of this-read only folder Using Outlook 4
O The Outlook API wrongfully shows an outlook folder to have zero sub-folders Outlook VBA and Custom Forms 1
O The Outlook API wrongfully shows an outlook folder to have zero sub-folders Outlook VBA and Custom Forms 2
S Outlook (2016 32bit; Gmail IMAP) - Save sent message to Outllook Folder Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
C VBA to prompt for Sent folder destination Outlook VBA and Custom Forms 3
G How to add a folder shortcut to outlook quick access toolbar? Using Outlook 6
G Add to Outlook Contacts - Point to non-default contacts folder Using Outlook 0
M Move to Folder Using Outlook 1
K Export Folder to PST Outlook VBA and Custom Forms 2
B Spam folder not showing in Outlook Using Outlook 5
D Is a sub folder under contacts necessary to be able to name an Address Book? Using Outlook 1
J Moved many emails to Outlook external folder, need to delete on Gmail server Using Outlook 14
A Going to folder using shortcuts Using Outlook 3
B Outlook 2016 Auto-archive creates new folder Using Outlook 3
B BCC issues after changing root folder path for gmail Using Outlook 1
Fozzie Bear Outlook 2016 Creating a shared local Contacts folder Using Outlook 2
A Cannot copy this folder because it may contain private items Using Outlook 0
A Unable to save recurring Meeting to Documents folder due to error Using Outlook 2
B Extracting email addresses from a folder - how to also get the name of the person the address is for? Using Outlook 5
E How to display "Change Folder" in Change Default Email Delivery Location in Exchange Outlook 2016 Using Outlook 1

Similar threads

Top