Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-19-2012, 10:22 PM
gsrikanth gsrikanth is offline FileSystemObject Compile Error: User-Defined Type Not Defined Windows XP FileSystemObject Compile Error: User-Defined Type Not Defined Office XP
Competent Performer
FileSystemObject Compile Error: User-Defined Type Not Defined
 
Join Date: Dec 2011
Posts: 133
gsrikanth is on a distinguished road
Default FileSystemObject Compile Error: User-Defined Type Not Defined


Code:
Dim FSO As New FileSystemObject


Private Sub Command1_Click()

  Dim fld As Folder
  Dim flds As Folders
  Dim fl As File

  With FSO
    
      Set fld = .GetFolder("D:\Projects Others\TZ-HASAN\WEB\images_upload")
      Dim f
      
      '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
Reply With Quote
  #2  
Old 04-20-2012, 01:30 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline FileSystemObject Compile Error: User-Defined Type Not Defined Windows 7 32bit FileSystemObject Compile Error: User-Defined Type Not Defined 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
  #3  
Old 03-28-2022, 06:32 AM
ashish128 ashish128 is offline FileSystemObject Compile Error: User-Defined Type Not Defined Windows 10 FileSystemObject Compile Error: User-Defined Type Not Defined Office 2019
Novice
 
Join Date: Mar 2022
Posts: 1
ashish128 is on a distinguished road
Default

Hi, I had the same issue and your guidance resolved it. Thanks



  • In the VBA IDE, go to Tools > References
  • Tick "Microsoft Scripting Runtime" and click OK
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileSystemObject Compile Error: User-Defined Type Not Defined Application-defined or Object-defined error Manit Excel Programming 4 12-08-2011 07:35 PM
Edit Multiple Emails' User-Defined Field ryancaseymcshane Outlook 0 10-04-2011 07:40 AM
Compile error: sub or function not defined.. xena2305 Excel Programming 0 08-02-2011 10:17 AM
FileSystemObject Compile Error: User-Defined Type Not Defined Why unable to use underscore in microsoft word styles( user defined)? noufalcm Word 1 03-08-2011 01:46 PM
FileSystemObject Compile Error: User-Defined Type Not Defined User Defined Default Settings in Insert J_oe Word 1 02-17-2011 10:55 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft