+ Reply to Thread
Results 1 to 2 of 2

Runtime Error 9 with VBComponents and Dir()

  1. #1
    Registered User
    Join Date
    03-08-2023
    Location
    Denver, Colorado
    MS-Off Ver
    Microsoft 365
    Posts
    1

    Question Runtime Error 9 with VBComponents and Dir()

    Hello,
    I am trying to get VBA to import a folder of .bas files into the PERSONAL.xlsb workbook upon Excel startup to ensure that users always have the most updated macros. Two lines of mine are throwing Runtime Error 9, and after playing around a bit I think it's either because I'm using Dir or there's something wrong with this line: *If IsNull(TargetWB.VBProject.VBComponents(fileNameNoExt)) = True Then Is Nothing Then*, but I'm not sure it that's what's wrong or how to fix it. (When I substitute an existing module name in quotes (no extension) for fileNameNoExt, there is no error in the AutoUpdateBasFiles sub, only in the DeleteVBComponent Sub. When I substitute a non-existent module name in quotes (no extension) for fileNameNoExt, it throws Runtime Error 9 again.) I am a novice with VBA. Any help or ideas would be appreciated.

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 03-28-2023 at 12:17 PM.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,918

    Re: Runtime Error 9 with VBComponents and Dir()

    Firstly fileName will never be null. You should be testing for it being equal to "" or vbNullString

    The error means that there is no vbcomponent with the specified name. Once again, your IsNull function will not handle that. You either need an error handler, or to simply loop through all the vbcomponents and test each one's name.

    For example:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    Rory

+ 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. [SOLVED] UBound coll error after converting macro. Runtime error 13. Type mismatch.
    By Elijah in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-30-2020, 05:08 AM
  2. [SOLVED] Runtime Error 1004 + Runtime 5
    By jrean042 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-07-2020, 08:16 AM
  3. [SOLVED] Runtime Error 1004 and Runtime Error 13
    By Brendan_MS in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-21-2020, 10:52 AM
  4. Runtime error 1004 & runtime error 424
    By MrWhiskey in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-29-2017, 08:57 AM
  5. [SOLVED] VBComponents question
    By Frederick Chow in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-20-2006, 03:25 PM
  6. Changeing codename of worksheet via VBComponents collection
    By Arne in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2005, 09:05 AM
  7. VBE window keeps opening when VBProject.VBComponents are created
    By dougal11179 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-22-2005, 09:48 AM

Tags for this Thread

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