Excel is complaining that it does not know what a FileSystemObject is. To use FileSystemObject you have to use a special reference which tells Excel where it can find out what FileSystemObject is.
- In the VBA IDE, go to Tools > References
- Tick "Microsoft Scripting Runtime" and click OK
I haven't tested your code, but you should move the FSO declaration into the procedure and create an instance of FileSystemObject on a separate line from where it is declared.
Code:
Private Sub Command1_Click()
Dim FSO As FileSystemObject
Dim fld As Folder
Dim flds As Folders
Dim fl As File
Set FSO = New FileSystemObject
With FSO
Set fld = .GetFolder("D:\Projects Others\TZ-HASAN\WEB\images_upload")
'MsgBox fld.Files.Count
For Each fl In fld.Files
If Right(fl.Name, 3) = "img" Then
fl.Name = Left(fl.Name, Len(fl.Name) - 3) & "gif"
End If
Next
End With
End Sub