thanks Kenneth. Unfortunately I do not know how to do this. If you could assist me further, that would be really appreciated.
thanks Kenneth. Unfortunately I do not know how to do this. If you could assist me further, that would be really appreciated.
![]()
'Code the open workbooks: Sub test() Dim wbk As Workbook, sFileName As String, sPath As String Dim i As Long, v() As Variant sPath = "C:\Users\M\Desktop\Test\" sFileName = sPath & "*.xlsx" 'Make a varaint array of filenames. v() = GetFileList(sFileName) For i = LBound(v) To UBound(v) 'Debug.Print v(i) Set wbk = Workbooks.Open(sPath & v(i)) Test_File_Exist_With_Dir_v1 Copy_To_Worksheets wbk.Close True Next i End Sub Function GetFileList(FileSpec As String) As Variant ' 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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks