If you need to use a Windows operating-system environment variable in a macro, you would use the Environ property. You can then use it in file paths, such as to save attachments or email to the user's My Documents folder.
Dim enviro As String enviro = CStr(Environ("USERPROFILE"))
For example, in the Save and Open Attachments macro, you could use the code snippet above to get the path to the user's folder instead of using shell32.
Instead of using this to get the file path:
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
You could use this:
Dim enviro As String enviro = CStr(Environ("USERPROFILE")) strFolderpath = enviro & "\OLAttachments\"
Or this:
Set oShell = CreateObject("WScript.Shell") strFolderpath = oShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Documents\"
For a complete list of the Environs, run this code and review the list in the Immediate windows (Ctrl+G)
Sub EnumSEVars() Dim strVar As String Dim i As Long For i = 1 To 255 strVar = Environ$(i) If LenB(strVar) = 0& Then Exit For Debug.Print strVar Next End Sub
Below is a list of some of the available environment variables, which are likely to be useful in Outlook programming. The can also by typed or pasted into the Address bar of Windows Explorer to jump to the folder location.
Shell Folder | Path |
---|---|
AppData (Windows XP, 7/8) | %USERPROFILE%\Application Data |
AppData (Windows 7/8 only) | %APPDATA% |
Local AppData (Windows XP, 7/8) | %USERPROFILE%\Application Data |
Local AppData (Windows 7/8 only) | %LOCALAPPDATA% |
Path to user's profile (e.g. C:\Users\{username}) | %HOMEPATH% |
Desktop | %USERPROFILE%\Desktop |
My Music (WinXP) | %USERPROFILE%\My Documents\My Music |
My Pictures | %USERPROFILE%\My Documents\My Pictures |
Personal [My Documents] (WinXP) | %USERPROFILE%\My Documents |
Personal [My Documents] (Windows 7/8) | %USERPROFILE%\Documents |
Templates (WinXP) | %USERPROFILE%\Templates |
Glad to find this article. Here's what I'd like to do -- organize what emails go to Outlook 2016 (Office 365 version) on 2 different machines. I have a machine for personal and educational stuff for which my company gives all of us a full MSDN license so we can keep our skills up. But -- no for profit work can be done with this.
So, my for profit work is done on another machine. I'd like to set up Outlook on both such that when I see a certain From address I can set up a rule for it from either machine. If it's educational, from either machine, put in that environment variable. If it's for profit, same deal from either machine.
Someone may have already thought of this. If not, if you've got some links that would save me search time, could you fire them my way? If there's a paid solution out there, say someone will sell their code for 100 bucks or so it's worth it to me to pay them for it.
Thanks,
Mike Durthaler
This is with an exchange mailbox? So you want to filter specific addresses to the profit folder, other addresses to the education folder? You could do this with Outlook's rules. Assuming exchange mailbox, they should be server-side rules and will work on all computers (they run as mail arrives, not when outlook downloads the mail).
If its more complicated than that, you could use either a run a script rule or an itemadd macro.
Hi Diane, Hope you are doing good. Coming back to you after 2 years of successful implementation of codetwo Properties :-) coupled with an excel macro to retrieve every 5 min of my teams responses. This time, i am inneed of putting environment variable inside shared email box so that i know who has responded. Is there a way to implement this particular thing in your code two proerties?
Thanks
Murugan
run the EnumSEVars macro and look at the immediate field for the list of environment variables available and the results. %username% will give you the logged in computer user, which is usually the user's folder name: c:\users\this-name. If users don't share workstation logons, this will be the easiest/shortest code. You could get the logged in mailbox name - i should have a code sample for that here somewhere.
Hi Diane,
Thanks for your reply and indeed I checked with EnumSEVars macro and tried to get the environment variable into a column in outlook. However i am getting my name as against the users who had actually sent the emails.
Please help.
Thanks
Murugan
if you want the sender's name you need to use item.sendername (where item is replaced by whatever you are using to refer to the message object) - that will get the display name the sender uses.
Hi Diane, Sorry i tried all these days only to fail :-(. I will explain you in detail.
1) have a Customer support team of 45 members working in Chennai, Banglore and Hyderabad using shared email account sharedemail@company.com
2) With your Extended Properties cfg file, i was able to figure out and track the turn around time of email responses inside outook.
3) have developed excel macro (with your support 2 years back) which runs every 5 minutes (with application.ontime method) and presents to the management (connected to big LCD screen) about the status of 3 locations - Pending, Time taken to respond, Replied or Forward.
4) However, recently there was an escalation about incorrect email response been made by some of our team member and dont know who had responded. I had to take a blame for that. So, to track that, i need your help in capturing the system name or user name by way of "Replied by User".
Hoping for solution :-)
Hi Diane,
Not sure whether my previous comment reached you but sorry i tried item.sendername but i am not getting. Infact i am actually looking like this..PR_Replier_Email_Address. This will easily fix my job whenever team responds incorrect email
The earlier comment is here, but i am way behind in answering. :(
Hi Diane
Sorry to bug you over this again and again. Any update on this :-).