|
-
Mar 7th, 2017, 12:54 AM
#1
Thread Starter
Addicted Member
Create User Interface Controls in VB.NET to use it in Excel
Hello guys,
I'm trying to create a simple Usercontrol in VB.NET to use it in Excel (32bit and 64bit).
The Usercontrol is having one Textbox and one Button.
When I try to insert it in Excel, it gives me this error:
"The selected file does not contain any self-registering activex controls"
In Application > Assembly Information > Make Assembly COM-visible - is checked
The code is:
Code:
Namespace ActiveXDotNet
Public Interface AxMyControl
Property UserText() As String
End Interface 'AxMyControl
Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Implements AxMyControl
Private mStr_UserText As String
Public Property UserText1() As String Implements AxMyControl.UserText
Get
Return mStr_UserText
End Get
Set(ByVal Value As String)
mStr_UserText = Value
'Update the text box control value also.
Me.TextBox1.Text = mStr_UserText
End Set
End Property
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show(Me.TextBox1.Text)
End Sub
Friend WithEvents TextBox1 As TextBox
Friend WithEvents Button1 As Button
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(89, 34)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(333, 20)
Me.TextBox1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(208, 76)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'UserControl1
'
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "UserControl1"
Me.Size = New System.Drawing.Size(497, 124)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
End Class
End Namespace
My projects:
Virtual Forms
VBA Telemetry
-
Mar 7th, 2017, 01:13 AM
#2
Fanatic Member
Re: Create User Interface Controls in VB.NET to use it in Excel
In Application > Assembly Information > Make Assembly COM-visible - is checked
I'm not sure what this does, but I can't see any code that would at least create Excel object. Is your Excel file opened during that ? Maybe this would help you out:
https://msdn.microsoft.com/en-us/lib...code-snippet-2
https://msdn.microsoft.com/en-us/lib.../ff838832.aspx
Last edited by LuckyLuke82; Mar 7th, 2017 at 01:17 AM.
-
Mar 7th, 2017, 03:58 AM
#3
Thread Starter
Addicted Member
Re: Create User Interface Controls in VB.NET to use it in Excel
LuckyLuke82 thank you for your response.
I'm trying to create a usercontrol (ActiveX control) that I can embed (insert) in Excel and then access it's properties, methods and events via VBA code.
This usercontrol I want to create, is like the ActiveX TextBox control that we can insert into the worksheet and change it's properties, methods and events from the VBA.
My projects:
Virtual Forms
VBA Telemetry
-
Mar 7th, 2017, 04:19 AM
#4
Fanatic Member
Re: Create User Interface Controls in VB.NET to use it in Excel
Any particular reason to use this from VB.NET ? You could create Userform in Excel and do same. If still from VB.NET then I think you should try AddShape method - though I don't see anywhere that UserControl is directly supported, but maybe you could design something near It using Autoshapes that are supported:
https://msdn.microsoft.com/en-us/lib.../ff821384.aspx
shapes:
https://msdn.microsoft.com/en-us/lib.../ff862770.aspx
Other than that I can't help you, I have never done anything simmilar. What is the actual purpose, is something conected to VB.NET app or what ? Handling with VBA and VB.NET might cause you some problems too.
-
Mar 7th, 2017, 06:32 AM
#5
Thread Starter
Addicted Member
Re: Create User Interface Controls in VB.NET to use it in Excel
I have created an ocx control (ActiveX control) in vb6 that can be used in Excel to automaticly create Userforms (Virtual Forms) with Grid control, Edit control, buttons group (for Add, Edit, Delete, Filter,.....), Relationships for Master-Detail (for eg. Order-OrderDetails).
With help of an external application that is also created with Virtual Forms (name: Virtual Forms Designer) the user scans worksheets (or database tables) and then, when this control is inserted into the Excel worksheet, the control builds the forms automaticly with help of this scaned data that is stored in an exteral file when we load this form form MainMenuTreeviw or from VBA.
(For example:
We insert the control onto the workbook.The control placed got the name: VirtualForm1
Then we can show the Virtual Form with this line of code:
Code:
Me.VirtualForm1.ShowVirtualForm ("frm1") )
The user can access the Textboxes, Lables, and other controls placed on this Virtual Forms from the VBA. The control also fires the Events like: BeforeEdit, AfterEdit, TextBox_change, Texbox_validate, CommandButton_click,....
You can see the control in action here (no sound):
#####################################
Because the control is created in vb6 it only works in 32-bit version of Excel,
now I want to recreate it in VB.NET so that the users be able to work with this control from 32 and 64-bit of Excel.
You can see other videos how to use this control here:
https://www.youtube.com/channel/UCtG...5cigD4Nd-EpS0g
Last edited by Davor Geci; Mar 7th, 2017 at 06:38 AM.
My projects:
Virtual Forms
VBA Telemetry
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|