Consulting

Results 1 to 4 of 4

Thread: Need help with VBA script and ActiveX command button

  1. #1
    VBAX Regular
    Joined
    Nov 2015
    Posts
    14
    Location

    Need help with VBA script and ActiveX command button

    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

  2. #2
    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.

    Clearform Test.docm

  3. #3
    VBAX Regular
    Joined
    Nov 2015
    Posts
    14
    Location
    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.

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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