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

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
V Folder Properties - Gmail account can't switch Using Outlook 5
Victor_50 Outlook 2019 Jump to folder from search folder Outlook VBA and Custom Forms 0
HarvMan Outlook 365 - Rule to Move an Incoming Message to Another Folder Using Outlook 4
S Email Macros to go to a SHARED Outlook mailbox Draft folder...NOT my personal Outlook Draft folder Using Outlook 2
I Help with Smart Folder + Query Builder on IMAP Using Outlook 0
S Paperclip icon shows without attachment in email under Sent folder Using Outlook 0
Kika Melo Outlook Calendar deleted appointments not in Deleted Items folder Using Outlook 3
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
G Adding a contact to a specific folder Using Outlook 0
Witzker Outlook 2019 Macro GoTo user defined search folder Outlook VBA and Custom Forms 7
Rupert Dragwater Duplicate email in Folder Using Outlook 7
S Adding a recipient's column to Sent folder in Outlook 2010 Outlook VBA and Custom Forms 1
L "Insert Pictures" Button-Wrong Folder Using Outlook 5
C Outlook 365 Copy/Save Emails in Folder Outside Outlook to Show Date Sender Recipient Subject in Header Using Outlook 0
Christopher M Outlook 365 Hey Diane! MS 365 Biz Standard and "Potential Spam" addressed to others coming to my JUNK folder? Using Outlook 2
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
A manual rule sends mail to wrong folder Using Outlook 5
richardwing Auto forward email that is moves into a specific outlook folder Outlook VBA and Custom Forms 5
D This folder up to date vs all folders up to date Using Outlook 1
G Automatically delete messages in the synchronization folder Outlook VBA and Custom Forms 4
wayneame Changing the Form Used by Existing Task Items in a Folder Outlook VBA and Custom Forms 4
S Need code to allow defined starting folder and selection from there to drill down Outlook VBA and Custom Forms 10
P Emails assigned with a certain category (within a shared inbox) to be copied to a specific folder. Outlook VBA and Custom Forms 2
M Saving emails using Visual Basic - Selecting folder with msoFileDialogFolderPicker Outlook VBA and Custom Forms 6
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
S Folder Pane Colour Categories Using Outlook 6
Victor.Ayala Automated way to check the option "Show this folder as an email Address Book" Outlook VBA and Custom Forms 2
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

Similar threads

Top