none
How to run an UserForm(VBE) using VBA interface in VSTO RRS feed

  • Question

  • I am writing an addin for excel using vsto.

    I have imported the UserForm file(.frm  vb5.0,which exported from VBA) to the VBProject. 

    But I don't know how to run the UserForm in Vsto. The similar code in VBA  is:

    '---------------------------------------

    Sub ShowForm()

    VBA.UserForms.add("formName").show

    End Sub

    '---------------------------------------

    My Vsto Code is as followed  (vb.net ):

    Dim vbpro As VBProject = ExcelApp.ActiveWorkbook.VBProject
    Dim comp As VBComponent

    comp = vbpro.VBComponents.Import("C:\\Udf.frm")

    'how to show the form?...

    '---------------------------------------

    Please help and thanks in advance


    Tuesday, November 4, 2014 2:20 PM

Answers

  • Thank you, Caillen Zhong

    My code in VBA is correct.

    I have got the reason.  Excel may crash only in version 2007. Excel2010 and 2013 will never happened!

    It seems something was wrong with Excel2007.

    It is the first time to ask help on MSDN. I am chinese, and my english is bad.

    Thank you , Everyone.

    Friday, November 7, 2014 2:10 AM

All replies

  • Hello Fang,

    VSTO doesn't provide anything for that.

    In the add-in you may call a VBA sub where the form is called. For example:

    Sub test() 
        Application.Run "ShowForm", yourWorksheet 
    End Sub
    
    Public Sub ShowForm() 
        loginform.Show 
    End Sub 

    You can read more about this in the How to dynamically add and run a VBA macro from Visual Basic article.

    Tuesday, November 4, 2014 2:42 PM
  • Thank you, Eugene Astafiev.

    I try it, and it works well. 

    But another problem is that it may cause the Excel Application to crash after I closed the running UserForm several minutes later.

    Excel application is crashed, and the pic shows the error modules is VBE6.DLL, the error code is C0000005.

    How to solve this problem? Await your reply.

    Wednesday, November 5, 2014 1:34 AM
  • Hi FangFangGeZi,

    Most likely there's some error in your VBA code, please check it out or post your code here.

    Take a look at this related thread:

    VBE6.DLL crashes Excel after VBA editing


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, November 6, 2014 6:19 AM
    Moderator
  • Thank you, Caillen Zhong

    My code in VBA is correct.

    I have got the reason.  Excel may crash only in version 2007. Excel2010 and 2013 will never happened!

    It seems something was wrong with Excel2007.

    It is the first time to ask help on MSDN. I am chinese, and my english is bad.

    Thank you , Everyone.

    Friday, November 7, 2014 2:10 AM