How to search a latest file in a folder with Marco? RRS feed

  • 問題

  • Dear all,

    How can I defined a marco which can search the latest file in the folder (in the floder = C:\test folder, file name = test_1.xls, test_2.xls,...), then copy a sheet to the other excel file's sheet (Original.xls -> sheets("Original"))?

    I defined a marco which can search the last data in a file then let me can auto-copy the latest file data to the file.

    Sub test()
    ' test Macro
    ' Keyboard Shortcut: Ctrl+u
        ' Find the last row of data
        finalrow = Range("A1048576").End(xlUp).Row
        'Loop Through each row
        For x = 5 To finalrow
         'decide if to copy based on column C
         thisvalue = Range("C" & x).Value
            If thisvalue = "" Then
            End If

        'I want to search the latest file in the folder, and the path should be the latest file eg. c:\test folder\test_1.xls
        Workbooks.Open Filename:="C:\test folder\test.xls", UpdateLinks:=0  

        NextRow = Range("A1048576").End(xlUp).Row + 1
        Cells(NextRow, 1).Select
    End Sub

    Thanks all and Best regards

    Kay Kuok
    2009年1月22日 3:25