Hello,
I am trying to make a macro to open a series of .csv files and copy data into the active workbook. The names of the files are different each time, with a common suffix.
An example file name would be "SPW2292-11-(A-B-C)-G_I13_C1_002-w-vFine-X-Top" where "SPW2292-11-(A-B-C)-G_I13_" will change each time.
Is there a way to open files with just the last section of the name?
Here is what I have now that will open the first file:
Filename = ThisWorkbook.Name
RunNo = Mid(Filename, 17, 6)
FilePath = ActiveWorkbook.FullName
FolderName = Mid(FilePath, 1, 29)
'MsgBox "RunNo is " & RunNo
'MsgBox "FilePath is " & FilePath
'MsgBox "FolderName is " & FolderName
Wafer = "W" + RunNo
WaferNo = "A-G"
SheetNo = "W" + Mid(RunNo, 1, 4) + "-" + Mid(RunNo, 5, 6) & WaferNo
If Dir("C:\X'Pert Data\Wafers\" & Wafer & "\" & SheetNo & "\" & "SPW2292-11-(A-B-C)-G_I13_C1_002-w-vFine-X-Top.csv") <> "" Then
SourceFile = "C:\X'Pert Data\Wafers\" & Wafer & "\" & SheetNo & "\" & "SPW2292-11-(A-B-C)-G_I13_C1_002-w-vFine-X-Top.csv"
Workbooks.Open Filename:=SourceFile
Range("A34:B34").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks(Filename).Activate
Sheets(WaferNo).Select
Range("A2").Select
ActiveSheet.Paste
Workbooks.Open Filename:=SourceFile
ActiveWorkbook.Close True
Else:
MsgBox "File not found."
End If
Bookmarks