Defining Userforms RRS feed

  • Question

  • I have the following module in VBA which is called by in a userform to save all control values if that control has a TAG that not blank. This sub is called by simply calling SaveFormToRegistry(me) when exiting the form.

    How do I dim a VSTO userform so that I can refer to it and save it to the registry, or is there a new and easier way to do this?

    Public Sub SaveFormToRegistry(FormName As UserForm)
    ' This procedure loops through all the controls on the user form which is passed to it
    ' If a control has a TAG then it saves the value of that control to the registry

    ' Get the name of the form
    s_FormString = FormName.Controls(1).Parent.Name

    On Error Resume Next
        ' See the registry entries already exist - Delete if exist
        v_MyRegSettings = GetAllSettings(s_RegistryName, s_FormString)
        If Not IsEmpty(v_MyRegSettings) Then DeleteSetting s_RegistryName, s_FormString
    On Error GoTo 0

    ' If a control has a TAG then save to registry
    For Each c_ControlX In FormName.Controls
        If c_ControlX.Tag <> "" Then SaveSetting s_RegistryName, s_FormString, c_ControlX.Tag, c_ControlX
    Next c_ControlX

    End Sub

    Sunday, August 11, 2013 2:02 AM

All replies

  • I'm a bit confused. The term "UserForm" applies only to VBA. VSTO, a .NET technology, doesn't have "UserForms". I think you need to provide more information in order for use to understand the context of your problem...

    Cindy Meister, VSTO/Word MVP, my blog

    Monday, August 12, 2013 12:52 PM
  • Hi Cindy.

    In VSTO one can insert a windows form.

    As my VBA code refers to a userform, how does one refer to a windows form, or rather, define an object by reference in a sub so that it can be manipulated by that sub.

    Monday, August 12, 2013 8:54 PM
  • Going through my Inbox, I realized that this discussion slipped through the cracks during a very busy time I had the last couple of months. Are you still stuck on this, or have you moved on?

    In VSTO, as should be done in VBA, you declare and instantiate a new instance of the Form's class in order to work with it...

    To go into any more depth, I'd need some kind of more exact example to understand what you're thinking of.

    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, October 16, 2013 3:40 PM