Dilema... Anyone think they could sort htis?

bsnapool

Active Member
Joined
Jul 10, 2006
Messages
452
Hi All

The problem.

I have code which summaires 73 files within one folder. what I would like to do is add to this code to apply a date when the file was last updated?

Anyone know how to solve this problem?

E.g. The code retreives data from a selected week. It retreives all sickness data, from all 73 files. I would like to add to the code to say when the last time the workbook was updated?

Any help would be really really appreciated.

The code is below:

Code:
Sub ListInfobyFile()
Dim wsSumm As Worksheet, WS As Worksheet
Dim Folderpath As String, Filenm As String, ActiveWB As String
Dim I As Long, R As Long, C As Long, lRowTo As Long, lRowEnd As Long
Dim V As Variant, ChWeek As Variant, vFileList As Variant

'Determine what tab to look in, A1 should have 1-52
'ChWeek = InputBox("What Week")
ChWeek = Application.InputBox(prompt:="What week?", Type:=2)

If IsNumeric(ChWeek) = False _
Or ChWeek < 1 _
Or ChWeek > 52 Then Exit Sub

Set wsSumm = Sheets("Summary")

lRowTo = wsSumm.Cells(Rows.Count, "A").End(xlUp).Row - 1

Range("A5").Select 'Start of the new list. Change as required

'Look in this file path to get a list of files in the folder, change this as required
Folderpath = ThisWorkbook.Path
Filenm = Dir(Folderpath & "\*.xls", vbNormal + vbReadOnly)

With Application
    .ScreenUpdating = False
    'Ensure macros dont fire when opening w/books
    .EnableEvents = False
End With

vFileList = GetFileList(Folderpath & "/*.xls")

If IsArray(vFileList) Then
    For I = LBound(vFileList) To UBound(vFileList)
        Filenm = vFileList(I)
    
        If ThisWorkbook.Name <> Filenm Then
            'Paste the name
            
            lRowTo = lRowTo + 2
            wsSumm.Cells(lRowTo, "A").Value = Filenm
            lRowTo = lRowTo + 1
            
            'open File
            Workbooks.Open FileName:=Folderpath & "\" & Filenm
            ActiveWB = ActiveWorkbook.Name
    
            Set WS = Nothing
            On Error Resume Next
            Set WS = Sheets(ChWeek)
            On Error GoTo 0
            If Not WS Is Nothing Then
    
                'Check Range
                'Get last row to check
                lRowEnd = WS.Range("B" & Rows.Count).End(xlUp).Row
    
                'Check for values in F:L
                For R = 12 To lRowEnd
                    For C = 6 To 12 'Cols F:L
                        If Application.IsNumber(WS.Cells(R, C)) Then 'Copy row to Summary
                            lRowTo = lRowTo + 1
                            wsSumm.Rows(lRowTo).Value = WS.Rows(R).Value
                            Exit For
                        End If
                    Next C
                Next R
            End If
            ActiveWorkbook.Close
        End If
    Next I
Else
    MsgBox "No Excel files found in " & Folderpath
End If

With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With
End Sub

Function GetFileList(FileSpec As String) As Variant
'  Courtesy John Walkenbach
'   Returns an array of filenames that match FileSpec
'   If no matching files are found, it returns False

    Dim FileArray() As Variant
    Dim FileCount As Integer
    Dim FileName As String
    
    On Error GoTo NoFilesFound

    FileCount = 0
    FileName = Dir(FileSpec)
    If FileName = "" Then GoTo NoFilesFound
    
'   Loop until no more matching files are found
    Do While FileName <> ""
        FileCount = FileCount + 1
        ReDim Preserve FileArray(1 To FileCount)
        FileArray(FileCount) = FileName
        FileName = Dir()
    Loop
    GetFileList = FileArray
    Exit Function

'   Error handler
NoFilesFound:
    GetFileList = False
End Function



Andrew
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
The reason for the duplicate post is not replys! I decided to try and make it easier for users to understand....

Is this not right?
 
Upvote 0
Andrew

No it's not right.:)

By duplicating posts you actually decrease the chances of getting help.

If the replies to the original post aren't helping then reply in that thread explaining why and include any further information if you think it's needed.

That will 'bump' it to the top.:)
 
Upvote 0

Forum statistics

Threads
1,225,064
Messages
6,182,645
Members
453,128
Latest member
mike4slund

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top