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.
Code:
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!
Bookmarks