Hello guys,
I written a code where it will open a file based on Prefix of a file name. But I need to open a file based on certain file name matches.
Example: If file name is RSNOS_20200906_Summary and if RSNOS_Summary matches with the file name then macro should open the file.
If file name is XYZ_20200906_datasheet and if XYZ_datasheet matches with the file name then macro should open the file.
Please someone help on this.
I written a code where it will open a file based on Prefix of a file name. But I need to open a file based on certain file name matches.
Example: If file name is RSNOS_20200906_Summary and if RSNOS_Summary matches with the file name then macro should open the file.
If file name is XYZ_20200906_datasheet and if XYZ_datasheet matches with the file name then macro should open the file.
Please someone help on this.
VBA Code:
Sub Openfile()
Dim Fso, fs, Fl
Dim pvtTbl As PivotTable
Set Fso = CreateObject("Scripting.FileSystemObject")
'Application.ScreenUpdating = False
For Each Fl In Fso.getfolder(ThisWorkbook.Path & "\").Files
If (InStr("RSNOS", Left(Fl.Name, 5)) = 1) Then 'for rawdata file
pa = ThisWorkbook.Path & "\"
inputfile = Fl.Name
Workbooks.Open (pa & inputfile)
End If
Next