Sunday, May 06, 2012

Word VBA add command buttons through code

Add CommandButton to Word Document using VBA (through AddOLEControl)
Here is one of the ways to add a command button on a Word document using Word VBA
Sub Macro_Add_Button()
Dim oCtl
Dim oCmd
Set oCtl = ActiveDocument.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")
Set oCmd = oCtl.OLEFormat.Object
oCmd.Caption = "Click Me..."
End Sub



3 comments:

  1. Anonymous9:02 AM

    What about the "Range" parameter for placement location? How do I set it to the end of the document?

    ReplyDelete
    Replies
    1. With AxSpreadsheet1.ActiveDocument.Application.Selection.Range.InlineShapes.AddOLEControl("Forms.CommandButton.1").OLEFormat.Object
      .caption = "eSig"
      End With

      Delete
  2. How i get a location of cursor click in word document for vb.net? or is there any property to create a button from vb.net code to word document at particular location?

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.