none
Convert Excel Spreadsheet controls to VB form

    Question

  • I am converting an Excel spreadsheet with VBA macros to VB.  I have been able to export all of the VBA macros (.frm, .cls, .bas), but cannot figure out how to export the controls embedded on an Excel spreadsheet to a VB form (e.g. =EMBED("Forms.CommandButton.1","").  I have buttons, check boxes, list boxes, etc. embedded in an Excel spreadsheet.  In the macro editor, I can see the controls in the object browser window. For example:

    cmdPrvFirst As CommandButton
        Member of VBAProject.Sheet1

    Copy/paste does not work.  How can I do this?  I hate to have to create the VB forms from scratch.

    Saturday, April 03, 2010 7:40 PM

Answers

  • Dave,

    I am not sure there is an easy way to do this.

    but what i suggest to maybe make it easier and not have to build everything manually is to use code to your advantage and write the designer code in your vba project then transfer it over to vb.net.

    In your vb.net project, solution explorer, click the show all files button at the top.  then open the designer.vb file for one of your forms.  you will see the designer code that creates your controls on the form.

    with a single button on a form it will look something like this
     

    Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(0, 0)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(75, 23)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    
      End Sub
      Friend WithEvents Button1 As System.Windows.Forms.Button
    

     
    look closely at all the button code, you can write this code yourself in the vba project, using vba code.  just get the properties of each control in your vba project and have it write code to match.

    Now, this might end up being more work than just doing the forms manually in vb.net project but if you have a lot of controls this can be faster.  you can also copy and paste the designer code, and change the names, locations, etc.

     if you do some searching you might should be able to find vba code to get all properties of a control.

    this is probably not what you are looking for but might help.  hope it does


    FREE
    DEVELOPER TOOLS     CODE     PROJECTS

    DATABASE CODE GENERATOR
    DATABASE / GENERAL  APPLICATION TUTORIAL
    Upload Projects to share or get help on and post the generated links here in the forum
    www.srsoft.us
    • Marked as answer by Jeff Shan Friday, April 09, 2010 5:48 AM
    • Marked as answer by Jeff Shan Friday, April 09, 2010 5:48 AM
    Saturday, April 03, 2010 8:39 PM