+ Reply to Thread
Results 1 to 6 of 6

Object 91 error in a code to find a file.

  1. #1
    Registered User
    Join Date
    04-15-2016
    Location
    Waxahachie, TX
    MS-Off Ver
    Office 2013
    Posts
    7

    Object 91 error in a code to find a file.

    Greetings,
    I am relatively new to vba and am looking for a way to search through a network and find a single file. I believe I have found it, however, I am unable to make the code run because I continually get the Object 91 error.

    In the picture you can see the code that I am trying to get to work. It uses the Microsoft scripting run time reference.

    The object is clearly defined as

    Dim oStartFolder as Scripting folder
    and the string to the folder I want to start as is likewise clearly defined. So, I am not sure what I am missing.

    Any help would be greatly appreciated.

    Thanks



    Sub FindFile()
    Dim oFolderStart As String
    Dim fso As Scripting.FileSystemObject
    Dim fil As Scripting.File
    Dim oStartFolder As Scripting.Folder
    Dim newfolderpath As String
    Dim subfol As Scripting.Folder

    oFolderStart = "T:\02 ESTIMATING & SALES\03 JOBS IN PROCESS"
    newfolderpath = "T:\TempDesignWorksheet"
    Set oStartFolder = fso.GetFolder(oFolderStart)

    For Each fil In oStartFolder.Files

    If Left(fso.GetFileName(fil.Path), 5) = "18000" And Left(fso.GetExtensionName(fil.Path), 2) = "xl" Then

    fil.Copy newfolderpath & "\" & fil.Name

    End If

    Next fil

    'For Each subfol In oStartFolder.SubFolders
    'FindFile (subfol.Path)
    'Next subfol
    End Sub
    Attached Images Attached Images

  2. #2
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: Object 91 error in a code to find a file.

    Maybe so, but I haven't checked
    Please Login or Register  to view this content.
    To do it for me and help me it is 2 different things!
    Sorry for my english, blame Google translator

  3. #3
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Object 91 error in a code to find a file.

    Welcome to the forum!

    Please use code tags and paste code between. Insert the tags by typing or clicking the # icon in the reply toolbar.

    You forgot to set the fso object.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    04-15-2016
    Location
    Waxahachie, TX
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Object 91 error in a code to find a file.

    Kenneth,
    You are correct Thanks for that!

    I then ran the code again with the three lines at the bottom not messaged out. Got this code

    Compile error: Wrong number of arguments or invalid property assignments.

    Any thoughts on that?

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Object 91 error in a code to find a file.

    You passed a value to the routine where it has none. Try adding an input parameter as a string and pass the first start folder in a Main() sub that calls it initially. Obviously, you would remove the string setup for the first folder's string. If still confused, I can show you how.
    Last edited by Kenneth Hobson; 05-25-2016 at 08:23 PM.

  6. #6
    Registered User
    Join Date
    04-15-2016
    Location
    Waxahachie, TX
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Object 91 error in a code to find a file.

    Something like this? I have this, however, it does not seem to pick up the input box. Any Ideas?



    Please Login or Register  to view this content.
    ok, figured out the input box issue. Moved the input box before the FindFile in the code. Works great!

    Thanks for your Help!
    Last edited by ljbaum; 05-26-2016 at 10:50 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Compile Error Cant find object
    By Dutchace in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2015, 04:33 AM
  2. Compile Error Cant find object
    By Dutchace in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-18-2015, 12:31 AM
  3. Path/File access error & Can't load or unload this object (Error 361)
    By WilliamWu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-28-2014, 12:05 PM
  4. [SOLVED] Getting Error 1004 Object or Application Defined Error - Code to rearrange data
    By BlazzedTroll in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-10-2013, 12:10 PM
  5. Error 424 Object Required Error when Using AddItem to ListBox Generated in Code
    By jclark419 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2010, 12:47 PM
  6. Compile Error - Can't Find Object or Library
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-06-2009, 07:23 AM
  7. Find Info code giving object failed error
    By Leah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-09-2009, 04:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1