Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7837907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:54:22+00:00 2026-06-02T14:54:22+00:00

I’m using VBA in Outlook 2010 and I’m trying to create a function that

  • 0

I’m using VBA in Outlook 2010 and I’m trying to create a function that will retrieve a selected user Home folder path from Active Directory.

The following code is a simple pop up that has the saving destination.

Sub SaveSelected()
'Declaration
Dim myItems, myItem, myAttachments, myAttachment
Dim myOrt As String
Dim myOLApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim objFSO As Object
Dim intCount As Integer

'Ask for destination folder
myOrt = InputBox("Destination", "Save Attachments", "\\server\home\VARIABLE\")
End Sub

I want the VARIABLE to come from AD depending on the currently selected email.
for example I received an email from Jimmy@home.com and then I select the email from jimmy@home.com, I want to be able to retrieve

\server\homedirectory\jimmy

and use “jimmy” as my VARIABLE.
If this is possible any help would be greatly appreciated.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:54:23+00:00Added an answer on June 2, 2026 at 2:54 pm

    THe follow code works

     

    Sub GetSelectedItems()
    
     Dim myOlExp As Outlook.Explorer
     Dim myOlSel As Outlook.Selection
     Dim mySender As Outlook.AddressEntry
     Dim oMail As Outlook.MailItem
     Dim oAppt As Outlook.AppointmentItem
     Dim oPA As Outlook.propertyAccessor
     Dim strSenderID As String
     Dim myOrt As String
     Dim user As String
    
     Const PR_SENT_REPRESENTING_ENTRYID As String ="http://schemas.microsoft.com/mapi/proptag/0x00410102"
    
     Set myOlExp = Application.ActiveExplorer
     Set myOlSel = myOlExp.Selection
    
    
     For x = 1 To myOlSel.Count
     If myOlSel.item(x).Class = OlObjectClass.olMail Then
     ' For mail item, use the SenderName property.
     Set oMail = myOlSel.item(x)
    
    
     ElseIf myOlSel.item(x).Class = OlObjectClass.olAppointment Then
     ' For appointment item, use the Organizer property.
     Set oAppt = myOlSel.item(x)
    
     Else
    
     Set oPA = myOlSel.item(x).propertyAccessor
     strSenderID = oPA.GetProperty(PR_SENT_REPRESENTING_ENTRYID)
     Set mySender = Application.Session.GetAddressEntryFromID(strSenderID)
    
     End If
     Next x
    
    
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    
    objConnection.Open "Provider=ADsDSOObject;"
    objCommand.ActiveConnection = objConnection
    
    strDomainName = "ou=company,dc=mydc,dc=com"
    strUserCN = oMail.SenderName & ""
    
    objCommand.CommandText = "<LDAP://" & strDomainName & ">;(&
    (objectCategory=person)(objectClass=user)(cn=" & strUserCN &
    "));samAccountName;subtree"
    
    Set objRecordSet = objCommand.Execute
    
    If Not objRecordSet.EOF Then
    
    user = objRecordSet.Fields("samAccountName")
    
    myOrt = InputBox("Destination", "Save Attachments", "\\server\home\" &user & "")
    
    
    End If
    
    objConnection.Close
    Set objRecordSet = Nothing
    Set objConnection = Nothing
    Set objCommand = Nothing
    
    'free variables
    Set myItems = Nothing
    Set myItem = Nothing
    Set myAttachments = Nothing
    Set myAttachment = Nothing
    Set myOLApp = Nothing
    Set myOlExp = Nothing
    Set myOlSel = Nothing
    Set user = Nothing
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using VBA to create a FileOpenDialog object so that the user can select
So hopefully that topic isn't too confusing, but basically using VBA within Outlook I
I basically want to open a browser window from Word using VBA that does
I am using Excel VBA 2003. Is it possible to create new recordset by
I am trying to get the current year using VBA. Is there any pre-build
Using VBA with a reference to Microsoft Scripting Runtime. I'm trying to compare filenames
The following Visio macro (using VBA) rotates the currently selected shape: ActiveWindow.Selection.Rotate90 How can
This is my first time using VBA in Outlook so please bear with me
I am trying to auto email a report from access using VBA in a
Using VBA with Access 2010, I have a sub: Public Sub setInterest(account As String,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.