The below code will loop through all the files within a selected folder whose name begins with "mi_" and ends with ".dbr". It will then search for all occurrences of the word "Rare" and replace it with "Quest". This is the same as using art manager to change the "ItemClassification" from "Rare" to "Quest". I finally got off my butt and decided to actually make this worth using. I edited the code below but it requires a userform to be created and placed within the userform's coding window.
What it does:
1. You select the number of search terms to use
2. Put those terms in the boxes labeled "Search for what?" i.e bat, or cat, or yeti
3. Put the text you want to replace it with in the boxes labeled "Replace with what?"
4. Click the checkbox if you want the program to cycle through all the subfolders
5. Click the "Browse" button to choose the folder to start in
6. Put an extension in the "File extension" text box, i.e. dbr. You don't have to use this feature but it can help if you are trying to narrow things down
7. The "OK" button starts, "Clear Form" clears the form, and "Exit" makes a sandwich
If you dont want to make a new userform I have also uploaded the document that contains both the macro and the userform here https://mega.nz/#F!300lGKzS!4DrmQZk6CWNQDeaU7GG76A
Just push the button to open the form. Be careful though, if you put an ambiguous search term in such as "X" or "mag" it will do its thing to ALL files that contain the letter "X" or files that contain the text "mag". However, this program only copies files and renames the copies so there shouldn't be an issue anyway.
Here is a pic of the form
https://mega.nz/#!Cl1DRIZb!eqJuYd_vzQTqrPkQ6dOILkQOtvD6-IL36h9hlXF0quM
Warning: If you are unfamiliar with VBA coding you should use this on a test project first. If you have questions on how to get started give me a shout. If enough people need to know I will edit this tutorial for beginners.
Option Explicit
Public fso As Object
Public MyNewFile As String
Public i As Integer
Public myPath As String
Public FldrPicker As FileDialog
Private Sub showme()
frmCopy_Rename.Show
End Sub
Private Sub Browsebtn_Click()
Application.ScreenUpdating = False
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show = 0 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
NextCode:
myPath = myPath
If myPath = "" Then
MsgBox "You must select a folder!"
Application.ScreenUpdating = True
Exit Sub
End If
End Sub
Sub SubFoldersloop(myFolder As Object)
Dim mySubFolder As Object
Dim myFile As Object
Dim Check(1 To 3)
Dim Rplace(1 To 3)
If SubFldrCheckBox.Value = True Then
For Each mySubFolder In myFolder.subfolders
SubFoldersloop mySubFolder
Next
End If
i = 1
Check(1) = CheckTextBox1.Value
Check(2) = CheckTextBox2.Value
Check(3) = CheckTextBox3.Value
Rplace(1) = RplaceTextBox1.Value
Rplace(2) = RplaceTextBox2.Value
Rplace(3) = RplaceTextBox3.Value
Cycle:
For Each myFile In myFolder.Files
If myFile Like "*" & Check(i) & "*" & extTextBox.Value Then
MyNewFile = Replace(myFile, Check(i), Rplace(i))
fso.copyfile myFile, MyNewFile
End If
DoEvents
Next
If NumbSearchesComboBox.Value > i Then
i = i + 1
GoTo Cycle
End If
End Sub
Private Sub Clearbtn_Click()
Call UserForm_Initialize
End Sub
Private Sub Exitbtn_Click()
Unload Me
End Sub
Private Sub OKbtn_Click()
Dim myFolder As Object
Set fso = CreateObject("Scripting.FileSystemObject")
SubFoldersloop fso.GetFolder(myPath)
MsgBox "Mission Success!"
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Initialize()
CheckTextBox1.Value = ""
CheckTextBox2.Value = ""
CheckTextBox3.Value = ""
RplaceTextBox1.Value = ""
RplaceTextBox2.Value = ""
RplaceTextBox3.Value = ""
NumbSearchesComboBox.Clear
With NumbSearchesComboBox
.AddItem "1"
.AddItem "2"
.AddItem "3"
End With
End Sub