PDA

View Full Version : Variable not defined error



juanbolas
01-10-2022, 11:22 AM
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.

arnelgp
01-10-2022, 06:26 PM
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.

Bob Phillips
01-11-2022, 02:31 PM
Do you set oVBProject anywhere?

juanbolas
01-12-2022, 06:18 AM
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.

Bob Phillips
01-12-2022, 12:26 PM
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

maruusa0106
02-26-2024, 09:42 PM
I also encountered this error but luckily I found a way to fix it.