View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_5_] Peter T[_5_] is offline
external usenet poster
 
Posts: 84
Default Referencing Userform in VB6

Pass a reference to the form from the Excel project to the dll.

' in Excel
dim frm as userform1
set frm = new userform1
set gVB6cls = new myVB6App.myClass

Set gVB6cls.objFrm = frm ' Public objFrm as Object
frm.show

Or maybe declare gVB6cls in the form and in the form's initialize event
set gVB6cls = new myVB6App.myClass
Set gVB6cls.objFrm = Me

In the myVB6App.myClass's initialize event set a global reference to self,
eg
Set gCls = Me

Also include something like this
Public Sub Bye()
' be sure to call this externally before destroying the class
set gCls = nothing
end sub

Now anywhere in your VB6 app you can refer to gCls.objFrm and
gCls.objFrm.myControl

In the form's unload event first call gVB6cls.Bye
then
Set gVB6cls = nothing

FWIW you can start your Excel form from VB6 using xlApp.Run, say to call a
procedure to load the userform and do the above.

Instead of passing the userform, objFrm, maybe it might be better to pass
references to the controls you know you will want to handle in the VB6 app.
In the VB6 you can't do -
Dim objFrm as Userform1
but you might be able to do
Dim myCtrl as ControlType ' ie early binding

Regards,
Peter T


"avi" wrote in message
...
Thanks everyone

I have a VBA application with some controls on UserForm1 of ActiveX
type, lets say CircleGauge1, CircleGauge2...

I want to be able to manipulate the controls property when the
Userform is in run mode, for example changing the color of
CircleGauge1

In order to it from VB6, I need that my VB6 program ( a dll) knows how
to refer to UserForm1 and to its controls. The VB6 dll is referenced
in Excel VBA

Thanks
Avi