Article ID: 185186
Article Last Modified on 1/22/2007
Sub AddACommandButtonWithCode()
Dim oButton
Set oButton =ActiveDocument.Shapes.AddOLEControl(Anchor:=Selection.
_
Range, ClassType:= "Forms.CommandButton.1")
With oButton.OLEFormat.Object
.Caption = "Great Feature:"
.Name = "myButtonOne"
End With
VBE.SelectedVBComponent.CodeModule.AddFromFile ("c:\buttoncode.txt")
ActiveDocument.Activate
Selection.Collapse
End Sub
Sub myButtonOne_Click
Msgbox "This code adds command button programmatically to document."
'Removes the button from the document.
ActiveDocument.Shapes(1).Delete
'Removes the lines of code text from the document.
Application.VBE.SelectedVBComponent.CodeModule.DeleteLines 1,7
End Sub
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: flow control vba toolbox design mode properties view code
Keywords: kbinfo kbprogramming KB185186