archanasinghvi
New Member
- Joined
- Dec 15, 2011
- Messages
- 6
Hi,
I have one requirement in which i have dynamically created oleobjects button through COMMAND BUTTON CLASS. Now what i want is i want to change their basic properties like backColor, Font etc through Modal form.
so i want to handle their DoubleClick event where i can get the Name of the buttons that be unique and then i can set the properties.
the thing is how can i get the Ids/Name of each button that is double clicked. as there is no argument for it.
I have written this code for dynAMICALLY GENERATING BUTTONS:
Sub AddButtonAndCode()
Try
act = Globals.ThisAddIn.Application.ActiveSheet
' Declare variables
Dim i As Long = 0, Hght As Long = 27
Dim Name As String, NName As String
'Dim oleObject As Excel.OLEObject
' Set the button properties
Hght = 305.25
' Set the name for the button
NName = "cmdAction" & i
' Test if there is a button already and if so, increment its name
Dim entry As KeyValuePair(Of String, Microsoft.Vbe.Interop.Forms.CommandButton)
If listOLEControls.Count > 0 Then
For Each entry In listOLEControls
If Microsoft.VisualBasic.Left(entry.Key, 9) = "cmdAction" Then
Name = Microsoft.VisualBasic.Right(entry.Key, Len(entry.Key) - 9)
If Name >= i Then
i = Name + 1
End If
End If
Next
Hght = entry.Value.Top + 27
End If
NName = "cmdAction" & i
' Add button
Dim myCmdObj As Microsoft.Office.Interop.Excel.OLEObject
myCmdObj = act.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=52.5, Top:=Hght, _
Width:=102.5, Height:=26.25)
' Define buttons name
myCmdObj.Name = NName
' Define buttons caption
' myCmdObj.Object.Caption = "Click for action"
'myCmdObj.d
myCmdObj.Object.Caption = NName
btn = myCmdObj.Object
' btn.DesignMode = True
AddHandler btn.MouseDown, AddressOf btn_MouseDown
AddHandler btn.MouseMove, AddressOf btn_MouseMove
listOLEControls.Add(NName, btn)
btn = Nothing
myCmdObj = Nothing
Catch ex As Exception
End Try
End Sub
I have one requirement in which i have dynamically created oleobjects button through COMMAND BUTTON CLASS. Now what i want is i want to change their basic properties like backColor, Font etc through Modal form.
so i want to handle their DoubleClick event where i can get the Name of the buttons that be unique and then i can set the properties.
the thing is how can i get the Ids/Name of each button that is double clicked. as there is no argument for it.
I have written this code for dynAMICALLY GENERATING BUTTONS:
Sub AddButtonAndCode()
Try
act = Globals.ThisAddIn.Application.ActiveSheet
' Declare variables
Dim i As Long = 0, Hght As Long = 27
Dim Name As String, NName As String
'Dim oleObject As Excel.OLEObject
' Set the button properties
Hght = 305.25
' Set the name for the button
NName = "cmdAction" & i
' Test if there is a button already and if so, increment its name
Dim entry As KeyValuePair(Of String, Microsoft.Vbe.Interop.Forms.CommandButton)
If listOLEControls.Count > 0 Then
For Each entry In listOLEControls
If Microsoft.VisualBasic.Left(entry.Key, 9) = "cmdAction" Then
Name = Microsoft.VisualBasic.Right(entry.Key, Len(entry.Key) - 9)
If Name >= i Then
i = Name + 1
End If
End If
Next
Hght = entry.Value.Top + 27
End If
NName = "cmdAction" & i
' Add button
Dim myCmdObj As Microsoft.Office.Interop.Excel.OLEObject
myCmdObj = act.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=52.5, Top:=Hght, _
Width:=102.5, Height:=26.25)
' Define buttons name
myCmdObj.Name = NName
' Define buttons caption
' myCmdObj.Object.Caption = "Click for action"
'myCmdObj.d
myCmdObj.Object.Caption = NName
btn = myCmdObj.Object
' btn.DesignMode = True
AddHandler btn.MouseDown, AddressOf btn_MouseDown
AddHandler btn.MouseMove, AddressOf btn_MouseMove
listOLEControls.Add(NName, btn)
btn = Nothing
myCmdObj = Nothing
Catch ex As Exception
End Try
End Sub