• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Identify particular word in File name

Abhijeet

Active Member
Hi

I have files from file name i want search particular word if match then i want to move that file to particular folder.
For Example 0H=Department Claim for Salary claim.pdf
Tp Depat claim 04.12.14 Travel claim.pdf

Search word Salary & Travel If Salary word match then move to salary folder
If Travel word match then move to Travel folder
Please tell me how to this
 
Setup a loop over your folder, and check the file name. To move the file, use a syntax like:
Code:
Name OldFileName As NewFileName
Make sure to include the full folder path with the name.
http://www.rondebruin.nl/win/s3/win026.htm

To check file names, you can use the InStr method
Code:
Sub ExampleCheck()
Dim searchedWord As String
Dim FindWord As String
searchedWord = "This is a sentence"
FindWord = "sentence"

'Check if findword is in searchedword
If InStr(1, searchedWord, FindWord, vbTextCompare) Then
    MsgBox "Found it"
End If
End Sub

Please, please take the time to review your many previous questions and answers. You should know by now how to loop over files. Take a shot at writing the code, and if you get stuck, post your code here, and we'll help you debug. This will benefit both you and us, as it will help you learn, and will save us time writing useless code, as I've seen in the past that you present the initial problem with a tiny view of what's going on, and then when we dive into the problem, you often start adding more scope to the work. If you take a crack at the code, since you already know the actual scope, you'll have a better chance of being able to address the different scenarios.
 
.....
Please, please take the time to review your many previous questions and answers. You should know by now how to loop over files. Take a shot at writing the code, and if you get stuck, post your code here, and we'll help you debug. This will benefit both you and us, as it will help you learn, and will save us time writing useless code, as I've seen in the past that you present the initial problem with a tiny view of what's going on, and then when we dive into the problem, you often start adding more scope to the work. If you take a crack at the code, since you already know the actual scope, you'll have a better chance of being able to address the different scenarios.

Well said @Luke M
 
Hi Luke M

Thanks for replay i have this macro for duplicate if any file then move to duplicate folder so how can i use this part of code replace against the Duplicate i use in attach file macro
Sub ExampleCheck()
Dim searchedWord AsString
Dim FindWord AsString
searchedWord = "This is a sentence"
FindWord = "sentence"

'Check if findword is in searchedwordIf InStr(1, searchedWord, FindWord, vbTextCompare) Then
MsgBox "Found it"
EndIf
EndSub
 

Attachments

  • Ver 1.2 Move_Duplicate_Files.xlsm
    22.1 KB · Views: 1
Starting in line 67 of the code, you can see where I made some changes.
 

Attachments

  • Ver 1.2 Move_Duplicate_Files LM.xlsm
    19.5 KB · Views: 3
Hi Luke M

I do not want Duplicate identify part in this macro i want search the word Travel & salary in file name if match then that file move to Salary or Travel folder.so please tell me
 
Then remove the If statement checking if the cell contains Duplicate. Could change it to something like
From this
If Cell().Value = "Duplicate" Then
to this
If Cell().Value <> "" Then
 
Hi Like M

Its Work but can u please tell me If Travel Or millage Or expense any word match then move to Travel Folder what should i do changes in code
 
As I wrote in the code, you would repeat the folder paths and repeat the ElseIf statements for each different location that you have.
 
Back
Top