+ Reply to Thread
Results 1 to 6 of 6

Retrieve File names from a folder with last modified username

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    4

    Retrieve File names from a folder with last modified username

    Hi Guys,

    My code is almost over, objective is need to retrieve File names with its Last Modified Date,Last Modified User,File Size into Excel...
    Everything is over but still am bottleneck to get Last Modified user's username
    Any idea on this ........thanks in advance


    Here is few piece of my code .... (code format will be in improper format dont mind that )
    Sub HyperlinkFileList()
         
        Dim fso As Object, _
        ShellApp As Object, _
        File As Object, _
        SubFolder As Object, _
        Directory As String, _
        Problem As Boolean, _
        ExcelVer As Integer
         Call Sheet1.CommandButton2_Click
         'Turn off screen flashing
        Application.ScreenUpdating = False
         
        Set fso = CreateObject("Scripting.FileSystemObject")
    
        Do
            Problem = False
            Set ShellApp = CreateObject("Shell.Application").BrowseForFolder(0, "Please choose a folder", 0, "c:\\")
             
            On Error Resume Next
            Directory = ShellApp.self.Path
            Sheet1.Range("D10").Value = Directory
        Call Module2.DirLoop
            Set SubFolder = fso.GetFolder(Directory).Files
            If Err.Number <> 0 Then
                If MsgBox("You did not choose a valid directory! Or Folder may be Empty!" & vbCrLf & _
                "Would you like to try again?", vbYesNoCancel, _
                "Directory Required") <> vbYes Then Exit Sub
                Problem = True
            End If
            On Error GoTo 0
        Loop Until Problem = False
         
    
        With ActiveSheet
            With .Range("D9")
                    .Parent.Hyperlinks.Add _
                    Anchor:=.Offset(1, 0), _
                    Address:=Directory, _
                    TextToDisplay:=Directory
            End With
        End With
         
         'Adds each file, details and hyperlinks to the list
        For Each File In SubFolder
            If Not Excludes(Right(File.Path, 3)) = True Then
            If Not Excludes(Mid(File.Name, 1, 2)) = True Then
                With ActiveSheet
                        .Hyperlinks.Add _
                        Anchor:=ActiveSheet.Range("D65536").End(xlUp).Offset(1, 0), _
                        Address:=File.Path, _
                        TextToDisplay:=File.Name
                      
                    With .Range("F65536").End(xlUp)
                        With .Offset(1, 0)
                            .Value = WorksheetFunction.Round(File.Size / 1024, 2)
                            .NumberFormat = "#,##0.00"
                        End With
                    End With
                End With
                End If
            End If
        Next
        
    End Sub
    Last edited by arlu1201; 01-05-2013 at 05:32 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Retrieve File names from a folder with last modified username

    impossible to test, missing Module2.DirLoop, attach file
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Retrieve File names from a folder with last modified username

    @patel45:
    you do have the code for Sheet1.CommandButton2_Click? Please show it as that call happens prior to what you mention. TIA.

    Ciao,
    Holger
    Last edited by arlu1201; 01-05-2013 at 05:32 AM. Reason: Put code tags for newbie.
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    09-11-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Retrieve File names from a folder with last modified username

    Hi Patel45
    Thanks for your reply Module2.DirLoop doesn't need for my requirement(i used just for testing the code in different way) , my code was not finished and also not in good format, it may confuse you ..... Any way if you get an idea to retrieve Username of Last Modified User for a file in a specified folder ..
    Thanks in Advance


    'sheet1
    Public Sub CommandButton2_Click()
    Range("B12:F1000").ClearContents
    Range("C10:F10").Value = ""
    End Sub
    
    
    'Module 2:
    
    Option Compare Text
    Option Explicit
    Public Directory As Object
    
    
    'Program to remove unwanted file names
    Function Excludes(Ext As String) As Boolean
         'Function purpose:  To exclude listed file extensions from hyperlink listing
         
        Dim X, NumPos As Long
         
         'Enter/adjust file extensions to EXCLUDE from listing here:
        X = Array("ini", "$")
         
        On Error Resume Next
        NumPos = Application.WorksheetFunction.Match(Ext, X, 0)
        'MsgBox NumPos & ">"
        If NumPos > 0 Then Excludes = True
        On Error GoTo 0
         
    End Function
    
    
    'To retrieve file hyperlink and File size
    
    Sub HyperlinkFileList()
         
        Dim fso As Object, _
        ShellApp As Object, _
        File As Object, _
        SubFolder As Object, _
        Directory As String, _
        Problem As Boolean, _
        ExcelVer As Integer
         Call Sheet1.CommandButton2_Click
         'Turn off screen flashing
        Application.ScreenUpdating = False
         
        Set fso = CreateObject("Scripting.FileSystemObject")
    
        Do
            Problem = False
            Set ShellApp = CreateObject("Shell.Application").BrowseForFolder(0, "Please choose a folder", 0, "c:\\")
             
            On Error Resume Next
            Directory = ShellApp.self.Path
            Sheet1.Range("D10").Value = Directory
        Call Module2.DirLoop
            Set SubFolder = fso.GetFolder(Directory).Files
            If Err.Number <> 0 Then
                If MsgBox("You did not choose a valid directory! Or Folder may be Empty!" & vbCrLf & _
                "Would you like to try again?", vbYesNoCancel, _
                "Directory Required") <> vbYes Then Exit Sub
                Problem = True
            End If
            On Error GoTo 0
        Loop Until Problem = False
         
    
        With ActiveSheet
            With .Range("D9")
                    .Parent.Hyperlinks.Add _
                    Anchor:=.Offset(1, 0), _
                    Address:=Directory, _
                    TextToDisplay:=Directory
            End With
        End With
         
         'Adds each file, details and hyperlinks to the list
        For Each File In SubFolder
            If Not Excludes(Right(File.Path, 3)) = True Then
            If Not Excludes(Mid(File.Name, 1, 2)) = True Then
                With ActiveSheet
                        .Hyperlinks.Add _
                        Anchor:=ActiveSheet.Range("D65536").End(xlUp).Offset(1, 0), _
                        Address:=File.Path, _
                        TextToDisplay:=File.Name
                      
                    With .Range("F65536").End(xlUp)
                        With .Offset(1, 0)
                            .Value = WorksheetFunction.Round(File.Size / 1024, 2)
                            .NumberFormat = "#,##0.00"
                        End With
                    End With
                End With
                End If
            End If
        Next
        
    
         
    End Sub
    
    
    
    'Module2
    'to retrieve only File name and Last Modified date
    
    Sub DirLoop()
    On Error Resume Next
    Dim fso As Object, _
        ShellApp As Object, _
        File As Object, _
        SubFolder As Object, _
        Directory As String, _
        Problem As Boolean, _
        ExcelVer As Integer
        Set fso = CreateObject("Scripting.FileSystemObject")
    
    Sheet1.Range("B12:F1000").ClearContents
    Dim MyFile As String, Sep As String, datefile As String
    Sep = Application.PathSeparator
    If Sep = "\" Then
    MyFile = Dir(Sheet1.Range("D10").Value & Sep & "*.*")
    End If
    datefile = FileDateTime(Sheet1.Range("D10").Value & "\" & MyFile)
    
    Dim i, j As Integer
    i = 12
    j = 1
    Do While MyFile <> ""
    Sheet1.Cells(i, 2).Value = j
    Sheet1.Cells(i, 3).Value = MyFile
    
    j = j + 1
    i = i + 1
    datefile = FileDateTime(Sheet1.Range("D10").Value & "\" & MyFile)
    Sheet1.Cells(i - 1, 5).Value = datefile
    MyFile = Dir()
    
    Loop
    
    End Sub

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Retrieve File names from a folder with last modified username

    Hi, elavarasans,

    AFAIR there´s no way of retrieving the name of the person which last saved the file via FSO (maybe have a look at Properties in FileSystemObject yourself). I only remember
    ActiveWorkbook.BuiltinDocumentProperties("Last Author").Value
    Cia,
    Holger

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Retrieve File names from a folder with last modified username

    elavarasans,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1