OK, I have an add-in with a public variable:
Dim VarABC as string
Now a Sub gets imported into the VBE from a text file. This textfile is just
completely unrelated to the add-in,
so the variables can be anything.
Now in this Sub in the textfile is a variable VarABZ. This really should be
VarABC, but it isn't.
Now when this Sub is imported the variable VarABZ isn't declared anywhere
(as the variable should be VarABC)
and there will be a compile error.
Can't make it any clearer. The more I think about it, the more I think there
is no solution for this other than
somehow scanning the whole textfile before importing it in the VBE.
RBS
"Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
news:42751BD7.E206F66C@netscapeXSPAM.com...
>I don't understand this sentence:
>
> "Then VarABZ is nowhere declared in the add-in and the compile error
> occurs."
> Because you said you had this in the addin:
>
> In Add-in:
> Public VarABC as String
>
> ==
> In my simple test, I had this in a text file:
>
> Option Explicit
> Sub test01A()
> VarABC = "hi"
> MsgBox VarABC
> End Sub
>
> In my other workbook, I had this in module1:
>
> Option Explicit
> Public VarABC As String
> Sub ImportTheTextFile()
> Dim myFileName As String
> myFileName = "C:\my documents\excel\test1.bas"
> ThisWorkbook.VBProject.VBComponents.Import myFileName
> Application.Run ThisWorkbook.Name & "!test01a"
> End Sub
>
> And it worked fine (xl2003).
>
> RB Smissaert wrote:
>>
>> I am not sure how that would work.
>> In it's most simple form this is how the situation is:
>>
>> In Add-in:
>>
>> Public VarABC as String
>>
>> Sub RunImportedSub()
>> Application.Run strImportedSub
>> End Sub
>>
>> In text file:
>>
>> Sub strImportedSub()
>> VarABZ = "test"
>> End Sub
>>
>> Then VarABZ is nowhere declared in the add-in and the compile error
>> occurs.
>> I can't alter the text files as they are with different people in
>> different
>> places.
>> All I can do is alter the add-in to deal with this.
>>
>> RBS
>>
>> "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
>> news:4274C20B.439BA9EB@netscapeXSPAM.com...
>> > If they're public variables, maybe you could put them in the same
>> > module
>> > so that
>> > their declaratations get imported, too.
>> >
>> > But I think I would try to rewrite the sub so that any variables that
>> > it
>> > needs
>> > are passed as parameters.
>> >
>> > Then I could just pass the parms I need in the line that calls the sub.
>> >
>> > RB Smissaert wrote:
>> >>
>> >> Do I conclude then that there is just no solution for this?
>> >>
>> >> RBS
>> >>
>> >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
>> >> news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
>> >> > Have the following situation:
>> >> > An .xla file will import a Sub from a text file and then run it like
>> >> > this:
>> >> >
>> >> > Dim strSub as String
>> >> >
>> >> > 'some code here to get the Sub imported
>> >> > Application.Run strSub
>> >> >
>> >> > Now it is possible that in this imported Sub are variables that are
>> >> > not
>> >> > defined publicly, so there
>> >> > will be a compile error, variable not defined.
>> >> > As this is not a runtime error I am not sure this error can be
>> >> > handled
>> >> > gracefully, but I would be interested
>> >> > in any suggestions how this could be done.
>> >> >
>> >> >
>> >> > RBS
>> >> >
>> >
>> > --
>> >
>> > Dave Peterson
>
> --
>
> Dave Peterson
Bookmarks