Hi guys I need help with my code.


I have following code to loop through a folder


Now is my problem.


I need to check in the folder if the first filename match another filename except the second filename have "_noTrans" in the end
then do message: the files match!




example of filenames:




TEST_Translation2_jeeves_sv.xls
TEST_Translation2_jeeves_sv_NoTrans.xls


TEST_Translation2_UCHPResourcesCommon_de.xls
TEST_Translation2_UCHPResourcesCommon_de_NoTrans.xls




When the script loops through the array,
if you find example:
TEST_Translation2_jeeves_sv.xls


Then if the script dont find the file:
TEST_Translation2_jeeves_sv_NoTrans.xls




The file ("TEST_Translation2_jeeves_sv_NoTrans.xls") is missing!


See code below:



Sub ListFiles()




Dim fd As FileDialog
Dim PathOfSelectedFolder As String
Dim SelectedFolder
Dim SelectedFolderTemp
Dim MyPath As FileDialog
Dim fs
Dim ExtraSlash
ExtraSlash = "\"
Dim MyFile




'Prepare to open a modal window, where a folder is selected
Set MyPath = Application.FileDialog(msoFileDialogFolderPicker)
With MyPath
'Open modal window
        .AllowMultiSelect = False
        If .Show Then
            'The user has selected a folder
            
            'Loop through the chosen folder
            For Each SelectedFolder In .SelectedItems




                'Name of the selected folder
                PathOfSelectedFolder = SelectedFolder & ExtraSlash
               
                Set fs = CreateObject("Scripting.FileSystemObject")
                Set SelectedFolderTemp = fs.GetFolder(PathOfSelectedFolder)
                    
                    'Loop through the files in the selected folder
                    For Each MyFile In SelectedFolderTemp.Files
                        'Name of file
                        
                        
                        JustFilN = Left(MyFile, (InStrRev(MyFile, ".", -1, vbTextCompare) - 1))
                      '  MsgBox JustFilN
                        
 
                        
                        'DO STUFF TO THE FILE, for example:
                        'Open each file:
                        'Workbooks.Open FileName:=MyFile
                        
                    Next       
                        
            Next
        End If
End With




End Sub

Could someone help me?


Thank you in advance