Hi .
i created vba code and get this error : Compile Error Invalid Outside Procedure
I know to start SUB and end as END SUB but i do not know where i did wrong.
I also used private SUB instead of only SUB but not working
Code is sth like this
Sub MVR_SEDAT()
Dim file As Variant
Dim path As String
Dim folderPath As String
Dim fileName As String
Dim searchName As String
' Set the path to the desktop folder
path = Environ("USERPROFILE") & "\Desktop"
' Set the folder path to move the files to
folderPath = "C:\Users\sedatcan\Desktop\SEDAT"
' Set the string to search for in the file names
searchName = "SEDAT"
' Loop through all files in the desktop folder
For Each file In CreateObject("Scripting.FileSystemObject").GetFolder(path).Files
' Check if the file name contains the search string
If InStr(file.Name, searchName) > 0 Then
' Get the file name
fileName = file.Name
' Move the file to the destination folder
FileCopy path & fileName, folderPath & fileName
' Delete the original file from the desktop
Kill path & fileName
End If
Next file
' Show a message when the operation is complete
MsgBox "All files containing " & searchName & " have been moved to " & folderPath
End Sub
Bookmarks