Consulting

Results 1 to 6 of 6

Thread: Variable not defined error

  1. #1

    Variable not defined error

    Hello,

    After a Windows 11 reinstall I've been having many problems with my custom VBA modules. This one has me stumped.

    I'm getting a 'Variable not defined' error when invoking oVBProject despite having VBA extensibility enabled.

    tFile = Dir(CodePath & FolderModules & "*.bas")
        Do While tFile <> ""
          lblComponent = tFile
          oVBProject.VBComponents.Import CodePath & FolderModules & tFile
          Count = Count + 1
          tFile = Dir
        Loop
    Thanks in advance for your kind help.

  2. #2
    it is best to Define your Variables before using them:
    Dim tFile As String, lblComponent As String
    Dim Count As Long
    tFile = Dir(CodePath & FolderModules & "*.bas")
        Do While tFile <> ""
          lblComponent = tFile
          oVBProject.VBComponents.Import CodePath & FolderModules & tFile
          Count = Count + 1
          tFile = Dir     Loop
    it is not really an Error.
    you have:

    Option Explicit

    on your module Declaration.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Do you set oVBProject anywhere?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Bob,

    As a matter of fact I don't set the variable. I understand its defined as part of the Extensibility resource. What would the variable definition look like?

    Bare in mind that this is a code snippet of a project that imports vb modules from my backup folder / library.

    Until I did a new windows install everything worked fine. I've checked and the Extensibility 5.3 and Scripting Runtime resources are installed (though I'm thinking they may not be working).

    Thanks in advance for your kind help.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Without seeing all the code I am guessing a bit, and your stating that all was well until a new windows install clouds the picture, but oVBProject must be a project object and needs to be set to some workbook's project accordingly. I would expect to see this somewhere in the code

        Set oVBProject = ThisWorkbook.VBProject
    or

        Set oVBProject = ActiveWorkbook.VBProject
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    I also encountered this error but luckily I found a way to fix it. slope

Tags for this Thread

Posting Permissions

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