Results 1 to 3 of 3

Create Command Button and format

Threaded View

dmeinder Create Command Button and... 04-16-2013, 04:55 PM
dmeinder Re: Create Command Button and... 04-17-2013, 10:31 AM
dmeinder Re: Create Command Button and... 04-18-2013, 10:26 AM
  1. #1
    Registered User
    Join Date
    11-16-2011
    Location
    Alberta
    MS-Off Ver
    2010
    Posts
    15

    Create Command Button and format

    Hello,
    I've been having a rough time getting this code to run properly in MS Word 2012. I'm trying to create a command button upon document open and modify it's properties.

    Private Sub Document_open()
    
    'Add a command button to a new document
        Dim doc As Word.Document
        Dim shp As Word.InlineShape
        Set doc = ActiveDocument
        
        Set shp = doc.Content.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")
        
        doc.InlineShapes(1).ConvertToShape
        
        'On Error Resume Next
        With CommandButton1
            .AutoSize = False
            .Caption = "Save & Close"
            .Enabled = True
            .Font = Calibri
            .Font.Bold = True
            .Font.Underline = False
            .Font.Size = 10
            .Height = 24
            .Left = 500
            .Locked = False
            .TakeFocusOnClick = True
            .Top = 25
            .Width = 72
        End With
        
    End Sub
    When stepping through the code I get the "can't enter break mode" when reaching the button creation line, this isn't so bad because the code still runs. I just wanted to mention in case it might help point to the problem.

    The reason I converted it to a shape is so I can access it's properties that require modification, however, upon reaching the "with" statement I get error 424 object required.

    The weird thing is that if I leave the button still in the document and run the code again it works fine (although it makes another button)....so it seems like maybe the cannot enter break mode is causing the code to not recognize the command button....or maybe it needs a delay or something.

    Any help is greatly appreciated....Thanks!
    Last edited by dmeinder; 04-17-2013 at 10:30 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1