+ Reply to Thread
Results 1 to 11 of 11

Addressing a UserForm sub in a VB dll

  1. #1
    Mangesh Yadav
    Guest

    Addressing a UserForm sub in a VB dll

    Hi,

    I have a userform call frmGraph, and currently in my excel application I am
    calling its initialise event something like this:
    frmGraph.UserForm_Initialize

    Now my problem is that, I am converting everything to a VB dll, and this
    particular line is giving me the error object not found. Preceding it with
    ThisWorkbook e.g.
    ThisWorkbook.frmGraph.UserForm_Initialize
    still does not solve the problem and gives the error "object does not
    support this property" which is ofcourse expected.

    How do I call this sub through my dll....?


    --
    - Mangesh
    ------------------------------------------
    Office 2003 & Windows XP



  2. #2
    Alasdair Stirling
    Guest

    RE: Addressing a UserForm sub in a VB dll

    Have a look at the following article:

    http://support.microsoft.com/default...;en-us;Q194611

    Regards,

    Alasdair Stirling

    "Mangesh Yadav" wrote:

    > Hi,
    >
    > I have a userform call frmGraph, and currently in my excel application I am
    > calling its initialise event something like this:
    > frmGraph.UserForm_Initialize
    >
    > Now my problem is that, I am converting everything to a VB dll, and this
    > particular line is giving me the error object not found. Preceding it with
    > ThisWorkbook e.g.
    > ThisWorkbook.frmGraph.UserForm_Initialize
    > still does not solve the problem and gives the error "object does not
    > support this property" which is ofcourse expected.
    >
    > How do I call this sub through my dll....?
    >
    >
    > --
    > - Mangesh
    > ------------------------------------------
    > Office 2003 & Windows XP
    >
    >
    >


  3. #3
    Mangesh Yadav
    Guest

    Re: Addressing a UserForm sub in a VB dll

    Hi Alasdair,

    Thanks for the response.

    Infact my problem does not relate much to the VB dll. Its rather basic. I
    want to know what is the parent of UserForm1.UserForm_Initialize

    or starting from ThisWorkbook and using intellisense, how can one arrive at
    UserForm1.UserForm_Initialize

    Something like:
    ThisWorkbook.SOMETHING.SOMETHING.UserForm1.UserForm_Initialize



    Mangesh


    "Alasdair Stirling" <[email protected]> wrote in
    message news:[email protected]...
    > Have a look at the following article:
    >
    > http://support.microsoft.com/default...;en-us;Q194611
    >
    > Regards,
    >
    > Alasdair Stirling
    >
    > "Mangesh Yadav" wrote:
    >
    > > Hi,
    > >
    > > I have a userform call frmGraph, and currently in my excel application I

    am
    > > calling its initialise event something like this:
    > > frmGraph.UserForm_Initialize
    > >
    > > Now my problem is that, I am converting everything to a VB dll, and this
    > > particular line is giving me the error object not found. Preceding it

    with
    > > ThisWorkbook e.g.
    > > ThisWorkbook.frmGraph.UserForm_Initialize
    > > still does not solve the problem and gives the error "object does not
    > > support this property" which is ofcourse expected.
    > >
    > > How do I call this sub through my dll....?
    > >
    > >
    > > --
    > > - Mangesh
    > > ------------------------------------------
    > > Office 2003 & Windows XP
    > >
    > >
    > >




  4. #4
    Mangesh Yadav
    Guest

    Re: Addressing a UserForm sub in a VB dll

    Anyone on this yet....

    Mangesh





    "Mangesh Yadav" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Alasdair,
    >
    > Thanks for the response.
    >
    > Infact my problem does not relate much to the VB dll. Its rather basic. I
    > want to know what is the parent of UserForm1.UserForm_Initialize
    >
    > or starting from ThisWorkbook and using intellisense, how can one arrive

    at
    > UserForm1.UserForm_Initialize
    >
    > Something like:
    > ThisWorkbook.SOMETHING.SOMETHING.UserForm1.UserForm_Initialize
    >
    >
    >
    > Mangesh
    >
    >
    > "Alasdair Stirling" <[email protected]> wrote in
    > message news:[email protected]...
    > > Have a look at the following article:
    > >
    > > http://support.microsoft.com/default...;en-us;Q194611
    > >
    > > Regards,
    > >
    > > Alasdair Stirling
    > >
    > > "Mangesh Yadav" wrote:
    > >
    > > > Hi,
    > > >
    > > > I have a userform call frmGraph, and currently in my excel application

    I
    > am
    > > > calling its initialise event something like this:
    > > > frmGraph.UserForm_Initialize
    > > >
    > > > Now my problem is that, I am converting everything to a VB dll, and

    this
    > > > particular line is giving me the error object not found. Preceding it

    > with
    > > > ThisWorkbook e.g.
    > > > ThisWorkbook.frmGraph.UserForm_Initialize
    > > > still does not solve the problem and gives the error "object does not
    > > > support this property" which is ofcourse expected.
    > > >
    > > > How do I call this sub through my dll....?
    > > >
    > > >
    > > > --
    > > > - Mangesh
    > > > ------------------------------------------
    > > > Office 2003 & Windows XP
    > > >
    > > >
    > > >

    >
    >




  5. #5
    Peter T
    Guest

    Re: Addressing a UserForm sub in a VB dll

    Hi Mangesh,

    Referring to your original question - you say you are converting everything
    to a vb6 dll, so why are you trying to call a vba userform from your dll. Is
    that indeed what you are trying to do?

    I don't follow why you want to call UserForm_Initialize(). This event, and
    code within, will run automatically as soon as you make the first reference
    to the Userform. Typically that might be Load or Show, but could be any sort
    of ref.

    Regards,
    Peter T

    "Mangesh Yadav" <[email protected]> wrote in message
    news:[email protected]...
    > Anyone on this yet....
    >
    > Mangesh
    >
    >
    >
    >
    >
    > "Mangesh Yadav" <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi Alasdair,
    > >
    > > Thanks for the response.
    > >
    > > Infact my problem does not relate much to the VB dll. Its rather basic.

    I
    > > want to know what is the parent of UserForm1.UserForm_Initialize
    > >
    > > or starting from ThisWorkbook and using intellisense, how can one arrive

    > at
    > > UserForm1.UserForm_Initialize
    > >
    > > Something like:
    > > ThisWorkbook.SOMETHING.SOMETHING.UserForm1.UserForm_Initialize
    > >
    > >
    > >
    > > Mangesh
    > >
    > >
    > > "Alasdair Stirling" <[email protected]> wrote

    in
    > > message news:[email protected]...
    > > > Have a look at the following article:
    > > >
    > > > http://support.microsoft.com/default...;en-us;Q194611
    > > >
    > > > Regards,
    > > >
    > > > Alasdair Stirling
    > > >
    > > > "Mangesh Yadav" wrote:
    > > >
    > > > > Hi,
    > > > >
    > > > > I have a userform call frmGraph, and currently in my excel

    application
    > I
    > > am
    > > > > calling its initialise event something like this:
    > > > > frmGraph.UserForm_Initialize
    > > > >
    > > > > Now my problem is that, I am converting everything to a VB dll, and

    > this
    > > > > particular line is giving me the error object not found. Preceding

    it
    > > with
    > > > > ThisWorkbook e.g.
    > > > > ThisWorkbook.frmGraph.UserForm_Initialize
    > > > > still does not solve the problem and gives the error "object does

    not
    > > > > support this property" which is ofcourse expected.
    > > > >
    > > > > How do I call this sub through my dll....?
    > > > >
    > > > >
    > > > > --
    > > > > - Mangesh
    > > > > ------------------------------------------
    > > > > Office 2003 & Windows XP
    > > > >
    > > > >
    > > > >

    > >
    > >

    >
    >




  6. #6
    Mangesh Yadav
    Guest

    Re: Addressing a UserForm sub in a VB dll

    Hi Peter,

    Thanks for your response.

    Basically I have an established excel application. And now I am turning some
    of the excel macros into VB dll. The line
    call UserForm1.UserForm_Initialize
    runs well in excel, but it gives an error in the dll. So my question was
    starting with ThisWorkbook, how do you arrive at UserForm1 using
    intellisense.

    For some reason, I want to run the Initialize event without an actual LOAD
    Form call.


    Mangesh




    "Peter T" <peter_t@discussions> wrote in message
    news:#[email protected]...
    > Hi Mangesh,
    >
    > Referring to your original question - you say you are converting

    everything
    > to a vb6 dll, so why are you trying to call a vba userform from your dll.

    Is
    > that indeed what you are trying to do?
    >
    > I don't follow why you want to call UserForm_Initialize(). This event, and
    > code within, will run automatically as soon as you make the first

    reference
    > to the Userform. Typically that might be Load or Show, but could be any

    sort
    > of ref.
    >
    > Regards,
    > Peter T
    >
    > "Mangesh Yadav" <[email protected]> wrote in message
    > news:[email protected]...
    > > Anyone on this yet....
    > >
    > > Mangesh
    > >
    > >
    > >
    > >
    > >
    > > "Mangesh Yadav" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Hi Alasdair,
    > > >
    > > > Thanks for the response.
    > > >
    > > > Infact my problem does not relate much to the VB dll. Its rather

    basic.
    > I
    > > > want to know what is the parent of UserForm1.UserForm_Initialize
    > > >
    > > > or starting from ThisWorkbook and using intellisense, how can one

    arrive
    > > at
    > > > UserForm1.UserForm_Initialize
    > > >
    > > > Something like:
    > > > ThisWorkbook.SOMETHING.SOMETHING.UserForm1.UserForm_Initialize
    > > >
    > > >
    > > >
    > > > Mangesh
    > > >
    > > >
    > > > "Alasdair Stirling" <[email protected]> wrote

    > in
    > > > message news:[email protected]...
    > > > > Have a look at the following article:
    > > > >
    > > > > http://support.microsoft.com/default...;en-us;Q194611
    > > > >
    > > > > Regards,
    > > > >
    > > > > Alasdair Stirling
    > > > >
    > > > > "Mangesh Yadav" wrote:
    > > > >
    > > > > > Hi,
    > > > > >
    > > > > > I have a userform call frmGraph, and currently in my excel

    > application
    > > I
    > > > am
    > > > > > calling its initialise event something like this:
    > > > > > frmGraph.UserForm_Initialize
    > > > > >
    > > > > > Now my problem is that, I am converting everything to a VB dll,

    and
    > > this
    > > > > > particular line is giving me the error object not found. Preceding

    > it
    > > > with
    > > > > > ThisWorkbook e.g.
    > > > > > ThisWorkbook.frmGraph.UserForm_Initialize
    > > > > > still does not solve the problem and gives the error "object does

    > not
    > > > > > support this property" which is ofcourse expected.
    > > > > >
    > > > > > How do I call this sub through my dll....?
    > > > > >
    > > > > >
    > > > > > --
    > > > > > - Mangesh
    > > > > > ------------------------------------------
    > > > > > Office 2003 & Windows XP
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >

    > >
    > >

    >
    >




  7. #7
    Mangesh Yadav
    Guest

    Re: Addressing a UserForm sub in a VB dll

    Now I have the following 3 macros in my excel application which is running
    fine

    My Excel macros:

    UserForm1 module : (2 macros below)
    Sub UserForm_Initialize()
    Call UFTest
    End Sub

    Sub UFTest()
    ' doing something
    End Sub

    Standard module: (1 macro in the standard module)
    Sub Main()
    UserForm1.UFTest
    End Sub

    Now I am converting the sub main to a vb dll, while keeping the userform
    macros untouched
    Sub Main(myApp)
    UserForm1.UFTest ' gives error "object required"
    End Sub

    In excel I would call this as:
    Call Main(ThisWorkbook)


    So my question is, in the VB code above how do I call the UFTest sub from
    the userform module...?



    Mangesh


    "Mangesh Yadav" <[email protected]> wrote in message
    news:O#[email protected]...
    > Hi Peter,
    >
    > Thanks for your response.
    >
    > Basically I have an established excel application. And now I am turning

    some
    > of the excel macros into VB dll. The line
    > call UserForm1.UserForm_Initialize
    > runs well in excel, but it gives an error in the dll. So my question was
    > starting with ThisWorkbook, how do you arrive at UserForm1 using
    > intellisense.
    >
    > For some reason, I want to run the Initialize event without an actual LOAD
    > Form call.
    >
    >
    > Mangesh
    >
    >
    >
    >
    > "Peter T" <peter_t@discussions> wrote in message
    > news:#[email protected]...
    > > Hi Mangesh,
    > >
    > > Referring to your original question - you say you are converting

    > everything
    > > to a vb6 dll, so why are you trying to call a vba userform from your

    dll.
    > Is
    > > that indeed what you are trying to do?
    > >
    > > I don't follow why you want to call UserForm_Initialize(). This event,

    and
    > > code within, will run automatically as soon as you make the first

    > reference
    > > to the Userform. Typically that might be Load or Show, but could be any

    > sort
    > > of ref.
    > >
    > > Regards,
    > > Peter T
    > >
    > > "Mangesh Yadav" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Anyone on this yet....
    > > >
    > > > Mangesh
    > > >
    > > >
    > > >
    > > >
    > > >
    > > > "Mangesh Yadav" <[email protected]> wrote in message
    > > > news:[email protected]...
    > > > > Hi Alasdair,
    > > > >
    > > > > Thanks for the response.
    > > > >
    > > > > Infact my problem does not relate much to the VB dll. Its rather

    > basic.
    > > I
    > > > > want to know what is the parent of UserForm1.UserForm_Initialize
    > > > >
    > > > > or starting from ThisWorkbook and using intellisense, how can one

    > arrive
    > > > at
    > > > > UserForm1.UserForm_Initialize
    > > > >
    > > > > Something like:
    > > > > ThisWorkbook.SOMETHING.SOMETHING.UserForm1.UserForm_Initialize
    > > > >
    > > > >
    > > > >
    > > > > Mangesh
    > > > >
    > > > >
    > > > > "Alasdair Stirling" <[email protected]>

    wrote
    > > in
    > > > > message news:[email protected]...
    > > > > > Have a look at the following article:
    > > > > >
    > > > > > http://support.microsoft.com/default...;en-us;Q194611
    > > > > >
    > > > > > Regards,
    > > > > >
    > > > > > Alasdair Stirling
    > > > > >
    > > > > > "Mangesh Yadav" wrote:
    > > > > >
    > > > > > > Hi,
    > > > > > >
    > > > > > > I have a userform call frmGraph, and currently in my excel

    > > application
    > > > I
    > > > > am
    > > > > > > calling its initialise event something like this:
    > > > > > > frmGraph.UserForm_Initialize
    > > > > > >
    > > > > > > Now my problem is that, I am converting everything to a VB dll,

    > and
    > > > this
    > > > > > > particular line is giving me the error object not found.

    Preceding
    > > it
    > > > > with
    > > > > > > ThisWorkbook e.g.
    > > > > > > ThisWorkbook.frmGraph.UserForm_Initialize
    > > > > > > still does not solve the problem and gives the error "object

    does
    > > not
    > > > > > > support this property" which is ofcourse expected.
    > > > > > >
    > > > > > > How do I call this sub through my dll....?
    > > > > > >
    > > > > > >
    > > > > > > --
    > > > > > > - Mangesh
    > > > > > > ------------------------------------------
    > > > > > > Office 2003 & Windows XP
    > > > > > >
    > > > > > >
    > > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >




  8. #8
    DM Unseen
    Guest

    Re: Addressing a UserForm sub in a VB dll

    The short explanation is: You should not do callback from VB into XL.
    i.e. when you have an XL addin that uses an VB DLL, the VB DLL should
    not use custom procedures or custom classes inside XL, this is an
    important design issue.

    This said, it is possible to do this, but with class modules this
    becomes very tricky. With Userforms i'm not even surer that this is
    possible without the following Hack(use at your own risk)

    In the XL addin set the following Macro:

    Public Function LoadUserForm(varForm As Variant) As Object

    Set LoadUserForm = VBA.UserForms.Add(varForm)
    ' see this reference is not available outside the XL VBA project!!!! so
    no way of opening an Userform from VB directly
    End Function

    in yout VB Code

    Sub Main(myapp as Workbook)
    Dim XL as Excel.Application

    Set XL = myapp.parent

    XL.run (myapp.name &"!LoadUserForm","UserForm1").UFTest
    ' runs the form with helper function in XL addin.
    End SUb


    Dm Unseen


  9. #9
    Peter T
    Guest

    Re: Addressing a UserForm sub in a VB dll

    Hi Mangesh,

    I still don't entirely follow what you are doing. As I mentioned before it's
    not necessary to explicitly call the vba Userform Intialize event, it will
    automatically run as soon as you make the first reference to the form.

    Maybe you can adapt something along the lines of this demo to your needs.
    However I don't know how to declare the vba userform in vb6, other than As
    Object, to get the userforms' intellisense in vb6.

    '' VB6 ActiveX dll named "QuickRef"
    '' code in Class named "hello" in QuickRef
    '' xlApp not used in this demo

    Dim xlApp As Excel.Application
    Dim oUF As Object
    Private vArr()

    Public Property Set prXLapp(xl As Excel.Application)
    Set xlApp = xl
    End Property
    Public Property Set prUF(uf As Object)
    Set oUF = uf
    End Property
    Public Sub Test()
    Dim n As Long
    n = oUF.prx
    MsgBox n, , "vb6 Test"
    oUF.prx = 333
    oUF.Commandbutton1.Caption = "Hide Me"
    oUF.Show
    MsgBox "Useform1 closed"
    End Sub
    Private Sub Class_Terminate()
    Set oUF = Nothing
    Set xlApp = Nothing
    End Sub

    '' vba normal module
    ''
    Dim vb6CL As QuickRef.hello
    Sub Main()
    Set vb6CL = New QuickRef.hello
    Set vb6CL.prXLapp = Application
    Set vb6CL.prUF = UserForm1
    vb6CL.Test
    MsgBox UserForm1.prX, , "vba Main"
    ClearUp
    End Sub

    Sub ClearUp()
    Set vb6CL = Nothing
    Unload UserForm1
    End Sub

    '' vba Userform1 with a button named "CommandButton12

    Dim x As Long
    Public Property Let prX(n As Long)
    x = n
    End Property
    Public Property Get prX() As Long
    prX = x
    End Property

    Private Sub CommandButton1_Click()
    Me.Hide
    End Sub

    1. set a value to form var' X in the initialize event
    2. get & display X in vb6
    3 vb6 change X
    4 vb6 change caption of form button
    5 display the new value X in vba

    Whilst this demo seems to work, I'm not at all sure it's a good way of doing
    things, at the least it's a bit odd!

    Regards,
    Peter T

    "Mangesh Yadav" <[email protected]> wrote in message
    news:[email protected]...
    > Now I have the following 3 macros in my excel application which is running
    > fine
    >
    > My Excel macros:
    >
    > UserForm1 module : (2 macros below)
    > Sub UserForm_Initialize()
    > Call UFTest
    > End Sub
    >
    > Sub UFTest()
    > ' doing something
    > End Sub
    >
    > Standard module: (1 macro in the standard module)
    > Sub Main()
    > UserForm1.UFTest
    > End Sub
    >
    > Now I am converting the sub main to a vb dll, while keeping the userform
    > macros untouched
    > Sub Main(myApp)
    > UserForm1.UFTest ' gives error "object required"
    > End Sub
    >
    > In excel I would call this as:
    > Call Main(ThisWorkbook)
    >
    >
    > So my question is, in the VB code above how do I call the UFTest sub from
    > the userform module...?
    >
    >
    >
    > Mangesh
    >
    >
    > "Mangesh Yadav" <[email protected]> wrote in message
    > news:O#[email protected]...
    > > Hi Peter,
    > >
    > > Thanks for your response.
    > >
    > > Basically I have an established excel application. And now I am turning

    > some
    > > of the excel macros into VB dll. The line
    > > call UserForm1.UserForm_Initialize
    > > runs well in excel, but it gives an error in the dll. So my question was
    > > starting with ThisWorkbook, how do you arrive at UserForm1 using
    > > intellisense.
    > >
    > > For some reason, I want to run the Initialize event without an actual

    LOAD
    > > Form call.
    > >
    > >
    > > Mangesh
    > >
    > >
    > >
    > >
    > > "Peter T" <peter_t@discussions> wrote in message
    > > news:#[email protected]...
    > > > Hi Mangesh,
    > > >
    > > > Referring to your original question - you say you are converting

    > > everything
    > > > to a vb6 dll, so why are you trying to call a vba userform from your

    > dll.
    > > Is
    > > > that indeed what you are trying to do?
    > > >
    > > > I don't follow why you want to call UserForm_Initialize(). This event,

    > and
    > > > code within, will run automatically as soon as you make the first

    > > reference
    > > > to the Userform. Typically that might be Load or Show, but could be

    any
    > > sort
    > > > of ref.
    > > >
    > > > Regards,
    > > > Peter T
    > > >
    > > > "Mangesh Yadav" <[email protected]> wrote in message
    > > > news:[email protected]...
    > > > > Anyone on this yet....
    > > > >
    > > > > Mangesh
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > > "Mangesh Yadav" <[email protected]> wrote in message
    > > > > news:[email protected]...
    > > > > > Hi Alasdair,
    > > > > >
    > > > > > Thanks for the response.
    > > > > >
    > > > > > Infact my problem does not relate much to the VB dll. Its rather

    > > basic.
    > > > I
    > > > > > want to know what is the parent of UserForm1.UserForm_Initialize
    > > > > >
    > > > > > or starting from ThisWorkbook and using intellisense, how can one

    > > arrive
    > > > > at
    > > > > > UserForm1.UserForm_Initialize
    > > > > >
    > > > > > Something like:
    > > > > > ThisWorkbook.SOMETHING.SOMETHING.UserForm1.UserForm_Initialize
    > > > > >
    > > > > >
    > > > > >
    > > > > > Mangesh
    > > > > >
    > > > > >
    > > > > > "Alasdair Stirling" <[email protected]>

    > wrote
    > > > in
    > > > > > message news:[email protected]...
    > > > > > > Have a look at the following article:
    > > > > > >
    > > > > > > http://support.microsoft.com/default...;en-us;Q194611
    > > > > > >
    > > > > > > Regards,
    > > > > > >
    > > > > > > Alasdair Stirling
    > > > > > >
    > > > > > > "Mangesh Yadav" wrote:
    > > > > > >
    > > > > > > > Hi,
    > > > > > > >
    > > > > > > > I have a userform call frmGraph, and currently in my excel
    > > > application
    > > > > I
    > > > > > am
    > > > > > > > calling its initialise event something like this:
    > > > > > > > frmGraph.UserForm_Initialize
    > > > > > > >
    > > > > > > > Now my problem is that, I am converting everything to a VB

    dll,
    > > and
    > > > > this
    > > > > > > > particular line is giving me the error object not found.

    > Preceding
    > > > it
    > > > > > with
    > > > > > > > ThisWorkbook e.g.
    > > > > > > > ThisWorkbook.frmGraph.UserForm_Initialize
    > > > > > > > still does not solve the problem and gives the error "object

    > does
    > > > not
    > > > > > > > support this property" which is ofcourse expected.
    > > > > > > >
    > > > > > > > How do I call this sub through my dll....?
    > > > > > > >
    > > > > > > >
    > > > > > > > --
    > > > > > > > - Mangesh
    > > > > > > > ------------------------------------------
    > > > > > > > Office 2003 & Windows XP
    > > > > > > >
    > > > > > > >
    > > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >




  10. #10
    Mangesh Yadav
    Guest

    Re: Addressing a UserForm sub in a VB dll

    Hi DM Unseen

    Thanks for the suggestions. Although at the first try, it doesn't seem to be
    working in my case (need to try harder, but no time at the moment). Will let
    you know about it all the same.

    Mangesh




    "DM Unseen" <[email protected]> wrote in message
    news:[email protected]...
    > The short explanation is: You should not do callback from VB into XL.
    > i.e. when you have an XL addin that uses an VB DLL, the VB DLL should
    > not use custom procedures or custom classes inside XL, this is an
    > important design issue.
    >
    > This said, it is possible to do this, but with class modules this
    > becomes very tricky. With Userforms i'm not even surer that this is
    > possible without the following Hack(use at your own risk)
    >
    > In the XL addin set the following Macro:
    >
    > Public Function LoadUserForm(varForm As Variant) As Object
    >
    > Set LoadUserForm = VBA.UserForms.Add(varForm)
    > ' see this reference is not available outside the XL VBA project!!!! so
    > no way of opening an Userform from VB directly
    > End Function
    >
    > in yout VB Code
    >
    > Sub Main(myapp as Workbook)
    > Dim XL as Excel.Application
    >
    > Set XL = myapp.parent
    >
    > XL.run (myapp.name &"!LoadUserForm","UserForm1").UFTest
    > ' runs the form with helper function in XL addin.
    > End SUb
    >
    >
    > Dm Unseen
    >




  11. #11
    Mangesh Yadav
    Guest

    Re: Addressing a UserForm sub in a VB dll

    Hi Peter,

    haven't tried this as yet, but will try soon.

    As for the intellisense part, my basic question is:
    from ThisWorkbook how to arrive at a userform in my workbook something like
    ThisWorkbook.SOMETHING.SOMETHING.UserForm1


    Mangesh




    "Peter T" <peter_t@discussions> wrote in message
    news:[email protected]...
    > Hi Mangesh,
    >
    > I still don't entirely follow what you are doing. As I mentioned before

    it's
    > not necessary to explicitly call the vba Userform Intialize event, it will
    > automatically run as soon as you make the first reference to the form.
    >
    > Maybe you can adapt something along the lines of this demo to your needs.
    > However I don't know how to declare the vba userform in vb6, other than As
    > Object, to get the userforms' intellisense in vb6.
    >
    > '' VB6 ActiveX dll named "QuickRef"
    > '' code in Class named "hello" in QuickRef
    > '' xlApp not used in this demo
    >
    > Dim xlApp As Excel.Application
    > Dim oUF As Object
    > Private vArr()
    >
    > Public Property Set prXLapp(xl As Excel.Application)
    > Set xlApp = xl
    > End Property
    > Public Property Set prUF(uf As Object)
    > Set oUF = uf
    > End Property
    > Public Sub Test()
    > Dim n As Long
    > n = oUF.prx
    > MsgBox n, , "vb6 Test"
    > oUF.prx = 333
    > oUF.Commandbutton1.Caption = "Hide Me"
    > oUF.Show
    > MsgBox "Useform1 closed"
    > End Sub
    > Private Sub Class_Terminate()
    > Set oUF = Nothing
    > Set xlApp = Nothing
    > End Sub
    >
    > '' vba normal module
    > ''
    > Dim vb6CL As QuickRef.hello
    > Sub Main()
    > Set vb6CL = New QuickRef.hello
    > Set vb6CL.prXLapp = Application
    > Set vb6CL.prUF = UserForm1
    > vb6CL.Test
    > MsgBox UserForm1.prX, , "vba Main"
    > ClearUp
    > End Sub
    >
    > Sub ClearUp()
    > Set vb6CL = Nothing
    > Unload UserForm1
    > End Sub
    >
    > '' vba Userform1 with a button named "CommandButton12
    >
    > Dim x As Long
    > Public Property Let prX(n As Long)
    > x = n
    > End Property
    > Public Property Get prX() As Long
    > prX = x
    > End Property
    >
    > Private Sub CommandButton1_Click()
    > Me.Hide
    > End Sub
    >
    > 1. set a value to form var' X in the initialize event
    > 2. get & display X in vb6
    > 3 vb6 change X
    > 4 vb6 change caption of form button
    > 5 display the new value X in vba
    >
    > Whilst this demo seems to work, I'm not at all sure it's a good way of

    doing
    > things, at the least it's a bit odd!
    >
    > Regards,
    > Peter T
    >
    > "Mangesh Yadav" <[email protected]> wrote in message
    > news:[email protected]...
    > > Now I have the following 3 macros in my excel application which is

    running
    > > fine
    > >
    > > My Excel macros:
    > >
    > > UserForm1 module : (2 macros below)
    > > Sub UserForm_Initialize()
    > > Call UFTest
    > > End Sub
    > >
    > > Sub UFTest()
    > > ' doing something
    > > End Sub
    > >
    > > Standard module: (1 macro in the standard module)
    > > Sub Main()
    > > UserForm1.UFTest
    > > End Sub
    > >
    > > Now I am converting the sub main to a vb dll, while keeping the userform
    > > macros untouched
    > > Sub Main(myApp)
    > > UserForm1.UFTest ' gives error "object required"
    > > End Sub
    > >
    > > In excel I would call this as:
    > > Call Main(ThisWorkbook)
    > >
    > >
    > > So my question is, in the VB code above how do I call the UFTest sub

    from
    > > the userform module...?
    > >
    > >
    > >
    > > Mangesh
    > >
    > >
    > > "Mangesh Yadav" <[email protected]> wrote in message
    > > news:O#[email protected]...
    > > > Hi Peter,
    > > >
    > > > Thanks for your response.
    > > >
    > > > Basically I have an established excel application. And now I am

    turning
    > > some
    > > > of the excel macros into VB dll. The line
    > > > call UserForm1.UserForm_Initialize
    > > > runs well in excel, but it gives an error in the dll. So my question

    was
    > > > starting with ThisWorkbook, how do you arrive at UserForm1 using
    > > > intellisense.
    > > >
    > > > For some reason, I want to run the Initialize event without an actual

    > LOAD
    > > > Form call.
    > > >
    > > >
    > > > Mangesh
    > > >
    > > >
    > > >
    > > >
    > > > "Peter T" <peter_t@discussions> wrote in message
    > > > news:#[email protected]...
    > > > > Hi Mangesh,
    > > > >
    > > > > Referring to your original question - you say you are converting
    > > > everything
    > > > > to a vb6 dll, so why are you trying to call a vba userform from your

    > > dll.
    > > > Is
    > > > > that indeed what you are trying to do?
    > > > >
    > > > > I don't follow why you want to call UserForm_Initialize(). This

    event,
    > > and
    > > > > code within, will run automatically as soon as you make the first
    > > > reference
    > > > > to the Userform. Typically that might be Load or Show, but could be

    > any
    > > > sort
    > > > > of ref.
    > > > >
    > > > > Regards,
    > > > > Peter T
    > > > >
    > > > > "Mangesh Yadav" <[email protected]> wrote in message
    > > > > news:[email protected]...
    > > > > > Anyone on this yet....
    > > > > >
    > > > > > Mangesh
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > > "Mangesh Yadav" <[email protected]> wrote in message
    > > > > > news:[email protected]...
    > > > > > > Hi Alasdair,
    > > > > > >
    > > > > > > Thanks for the response.
    > > > > > >
    > > > > > > Infact my problem does not relate much to the VB dll. Its rather
    > > > basic.
    > > > > I
    > > > > > > want to know what is the parent of UserForm1.UserForm_Initialize
    > > > > > >
    > > > > > > or starting from ThisWorkbook and using intellisense, how can

    one
    > > > arrive
    > > > > > at
    > > > > > > UserForm1.UserForm_Initialize
    > > > > > >
    > > > > > > Something like:
    > > > > > > ThisWorkbook.SOMETHING.SOMETHING.UserForm1.UserForm_Initialize
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > > Mangesh
    > > > > > >
    > > > > > >
    > > > > > > "Alasdair Stirling" <[email protected]>

    > > wrote
    > > > > in
    > > > > > > message

    news:[email protected]...
    > > > > > > > Have a look at the following article:
    > > > > > > >
    > > > > > > >

    http://support.microsoft.com/default...;en-us;Q194611
    > > > > > > >
    > > > > > > > Regards,
    > > > > > > >
    > > > > > > > Alasdair Stirling
    > > > > > > >
    > > > > > > > "Mangesh Yadav" wrote:
    > > > > > > >
    > > > > > > > > Hi,
    > > > > > > > >
    > > > > > > > > I have a userform call frmGraph, and currently in my excel
    > > > > application
    > > > > > I
    > > > > > > am
    > > > > > > > > calling its initialise event something like this:
    > > > > > > > > frmGraph.UserForm_Initialize
    > > > > > > > >
    > > > > > > > > Now my problem is that, I am converting everything to a VB

    > dll,
    > > > and
    > > > > > this
    > > > > > > > > particular line is giving me the error object not found.

    > > Preceding
    > > > > it
    > > > > > > with
    > > > > > > > > ThisWorkbook e.g.
    > > > > > > > > ThisWorkbook.frmGraph.UserForm_Initialize
    > > > > > > > > still does not solve the problem and gives the error "object

    > > does
    > > > > not
    > > > > > > > > support this property" which is ofcourse expected.
    > > > > > > > >
    > > > > > > > > How do I call this sub through my dll....?
    > > > > > > > >
    > > > > > > > >
    > > > > > > > > --
    > > > > > > > > - Mangesh
    > > > > > > > > ------------------------------------------
    > > > > > > > > Office 2003 & Windows XP
    > > > > > > > >
    > > > > > > > >
    > > > > > > > >
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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