Hi!
I'm making a macro who's supposed to add custom controls to a commandbar via an input field. The string the user inputs in the field is supposed to be the caption of the control and the name of a new textstyle. Further when a user clicks this particular control it's supposed to write it's own caption in the right style.
I guess when a user clicks a commandbar control it have to send it's own id so that I can get it's caption and then select the style and write the text....
Is this possible? -and how?
here's my code so far:
Thanx!
Pål Nesteby
PDC-Tangen
Norway
I'm making a macro who's supposed to add custom controls to a commandbar via an input field. The string the user inputs in the field is supposed to be the caption of the control and the name of a new textstyle. Further when a user clicks this particular control it's supposed to write it's own caption in the right style.
I guess when a user clicks a commandbar control it have to send it's own id so that I can get it's caption and then select the style and write the text....
Is this possible? -and how?
here's my code so far:
Code:
For the userform:
Private Sub CommandButton1_Click()
'Here comes the text from the user input
ButtonInit(TextBox1.Text)
UserForm1.hide
End Sub
For the buttonInit function:
Function buttonInit(ByVal text As String)
ActiveDocument.Styles.Add ("Type_" + text)
ActiveDocument.Styles("type_" + text).Font.Bold = True
ActiveDocument.Styles("type_" + text).Font.Color = wdColorBlue
Dim buttonName
buttonName = "type_" + text
Set buttonName = CommandBars("My Menu").Controls.Add(Type:=msoControlButton)
With buttonName
.Caption = text
.OnAction = prosessText(<Here should the id of the control come I guess>)
End With
End Function
The prosessText function:
Function prosessText(byVal id as String)
dim text
text = Commanbars("My menu").controls(id).caption
Selection.TypeText Text:=text
Selection.Style = ActiveDocument.Styles("type_" + text)
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Function
Thanx!
Pål Nesteby
PDC-Tangen
Norway