Solved

Excel VBA - How to find out how create the windows folder or directory.

Posted on 2011-09-26
6
583 Views
Last Modified: 2012-05-12
Hi Experts,

Can you please help guilde me in the right direction with vba coding to extract the "Author" property from a Windows directory. I need to know who created the folder that sits on a local drive.

I'm currently doing this manually as can be seen in attached image.
Thanks in advance.
Ric Folder's Author
0
Comment
Question by:RiCzN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 42

Expert Comment

by:dlmille
ID: 36648402
Here's an excellent tip to access file properties, including author:

http://www.codeguru.com/forum/showthread.php?t=372929


Dave
0
 
LVL 42

Expert Comment

by:dlmille
ID: 36652789
You need to add a reference to the Microsoft Shell Controls and Automation library to use the shell objects in the getFileAttributes() function...

This gives you file properties, of course.  I'm checking to see if folder properties are also available...

0
 
LVL 42

Expert Comment

by:dlmille
ID: 36663932
I'm finding all kinds of sources listing folder properties.  None of them mention author.  I don't think I have ever seen it.  Sorry for the question, but can you show an image of an author associated with a folder?  I tried what you did on my machine and get null results.

Thanks for the clarification.

Cheers,

Dave
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 42

Accepted Solution

by:
dlmille earned 500 total points
ID: 36704140
Ok.  I think I've got it.  I'm not sure what your picture is showing will give you the author of the folder.  However, if you right click the folder, then left-click on properties, navigate to the security tab and click "Advanced", then go to the OWNER tab, you'll see who the current owner is.  Unless ownership was transferred after creation, it should give you either the user or the user's group (e.g., if the user was an Administrator, it might list Administrators as the owner) as the author/owner.

Please take a look at this:

The function makes use of the ADsSecurityUtility object, which is in the Active DS Type Library.  The code uses late binding, but you can investigate the object via google - plenty of sources once you know what to search for, and also via VBA Watch window.

Here's the code:
 
Option Explicit
Sub getFolderAuthor()
Dim fPath As String

    fPath = GetFolderName("Select Folder for Author/Owner identification")
    If fPath <> "" Then
        MsgBox "The Author/Owner of Folder: " & fPath & " is: " & GetFolderFileOwner(fPath)
    End If
    
End Sub
Function GetFolderFileOwner(fileDir As String, Optional fileName As String) As String

    'On Error Resume Next
    Dim secUtil As ADsSecurityUtility
    Dim secDesc As Object
    Set secUtil = CreateObject("ADsSecurityUtility")
    Set secDesc = secUtil.GetSecurityDescriptor(fileDir & fileName, 1, 1)
    
    GetFolderFileOwner = secDesc.Owner
End Function

Open in new window


I included a test subroutine, which is called when you click the button on the attached workbook - select a folder and it will provide the owner/author back as a result of the getSecurityDescriptor interrogation.

Let me know this works for you.  On my machine, I'm an admin, so all my files are owned by the group "Administrators".  I'd like to know if you get user names or only the group where they reside...

Cheers,

Dave
getFolderFileOwnerAuthor-r1.xlsm
0
 

Author Comment

by:RiCzN
ID: 36708735
Hi Dave, thanks for the quick reply. I wasnt expecting anyone to get back to me so quickly. Ill give your suggestions a go when im in the office tomorrow. Thanks once again.
0
 

Author Closing Comment

by:RiCzN
ID: 36907989
Thanks very much Dave!!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question