View Single Post
 
Old 04-20-2012, 01:30 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Jan 2011
Location: UK
Posts: 369
Colin Legg will become famous soon enough
Default

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
__________________
Colin

RAD Excel Blog
Reply With Quote