jme851
New Member
- Joined
- Jan 27, 2014
- Messages
- 7
I need help with vba code, I need to move files that contain "CSC" in the file name to another folder, there .pdfs. The orginal folder will have pdfs names simlar to but not limited 123456_256_2022526 or CN_CSC 20220506 or CS_CSC 1234567890_222222 or C_CSC 23456158_222234. I only need to move the files with the CSC. I pulled some code from somethings my prior boss did before he left, it didn't work, I've search and just can't find anything that works. Hope someone can help .
this is the code with variations of the If Trim. I've tried several different codes from online with no luck.
this is the code with variations of the If Trim. I've tried several different codes from online with no luck.
VBA Code:
Sub test()
MyFolder = "C:\DMC\Prod\Archive\archive_lmr"
MyFile = Dir(MyFolder & "*.PDF")
Do While MyFile <> ""
If Trim(Split(MyFile, "_")(1)) = "CSC " Then
Name MyFolder & MyFile As "C:\DMC\Prod\Archive\NA Docs\" & MyFile
End If
Loop
End Sub