PDA

View Full Version : Need help with VBA script and ActiveX command button



limdul
12-02-2015, 03:12 PM
Hi everyone,

So I have seen this script from Greg Maxey and it works almost perfectly. The only issue I am seeing is that after I press the command button that this script is attached to it will not allow me to type in any plain text content control boxes on my form. The only way that I have found that it will let me type again is if I triple click in the text box rapidly. Does anyone know of why it would do that and if so is there a way to stop that from happening. I would appreciate any help that people will give.

Private Sub Clearform_Click()
'A quick macro scratch pad created by Greg Maxey
Dim oCC As ContentControl
For Each oCC In ActiveDocument.ContentControls
Select Case oCC.Type
Case 0, 1
oCC.Range.Text = ""
Case 4
oCC.DropdownListEntries(1).Select
Case 8
oCC.Checked = False
End Select
Next oCC
End Sub

MacroWizard
12-02-2015, 05:34 PM
limdul,

I checked the code out myself and it works just fine for me and I can edit my textboxes/richtext/comboboxes with a single click. Attached is the test document for your reference purposes. See if the macro works for you. If it doesn't, we can confidently say that there is a setting somewhere in word that you have set that is creating the problem.

14864

limdul
12-03-2015, 09:33 AM
Yea it works great on that form. Do you think it is because I have so many content controls in my doc. It is 4 pages long of tables and has upwards of 300 - 400 dropdown content controls and about 100 - 150 plain text content controls and 5 date content controls.

gmaxey
12-03-2015, 06:37 PM
You won't be able to type until the code executes and depending on your processor speed that may take several seconds. I ran

Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oCC As ContentControl
Dim I As Long
Dim oRng As Word.Range
For I = 1 To 150
Set oRng = ActiveDocument.Range
oRng.Collapse wdCollapseEnd
oRng.InsertBefore vbCr
ActiveDocument.ContentControls.Add wdContentControlText, oRng
Next
For I = 1 To 400
Set oRng = ActiveDocument.Range
oRng.Collapse wdCollapseEnd
oRng.InsertBefore vbCr
Set oCC = ActiveDocument.ContentControls.Add(wdContentControlDropdownList, oRng)
oCC.DropdownListEntries.Add "Test", "Test'"
oCC.DropdownListEntries.Add "XXX", "XXX"
Next
For I = 1 To 5
Set oRng = ActiveDocument.Range
oRng.Collapse wdCollapseEnd
oRng.InsertBefore vbCr
ActiveDocument.ContentControls.Add wdContentControlDate, oRng
Next
lbl_Exit:
Exit Sub
End Sub

To add the CCs and it takes my PC about 1.5 seconds to process the clear code.