Excel VBA insert & set properties of an ActiveX checkbox, copy it and past it into a Word table column in multiple rows

Satbirdhil

New Member
Joined
Jul 1, 2021
Messages
2
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2011
  5. 2010
  6. 2007
Platform
  1. Windows
MS 365 Apps for enterprise Version 2008 (Build 13127.21624). I can successfully add check boxes into a word table column in multiples rows with the code below.
However this is very slow. I thought it might be quicker to insert one checkbox, set its size to the size I want and then past it a multiple times into column '8' of the WdClothingform table in each subsequent row. The code successfully produces the result I want but it takes a very long time. The commented out code is one version of my many unsuccessful attempts at trying to copy that checkbox and then paste it.
i) How may I copy am ActiveX checkbox and paste it multiple times?
ii) Is there another faster way to produce the result I want.

For tblrow = 2 To WdClothingForm.RowS.count Step 1
WdClothingForm.Cell(tblrow, 8).Select

' Set chk = Wapp.Selection.InlineShapes.AddOLEControl(ClassType:="Forms.CheckBox.1")
'
' chk.Width = 11: chk.Height = 11
' Selection.copy
' chk.OLEFormat.Object.Activate
' Selection.copy
'
' WdClothingForm.Cell(3, 8).Select
' Selection.Paste
' chk.OLEFormat.Object.Paste

Set chk = Wapp.Selection.InlineShapes.AddOLEControl(ClassType:="Forms.CheckBox.1")
With chk.OLEFormat.Object
.Width = 11
.Height = 11
.Name = "ChkBx" & i - 1
End With

Next tblrow

Thank in advance for your help?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
There's no need to do any selecting, nor is there any need to do any copying and pasting. These will make things much more inefficient. Also, in order to speed things up, ScreenUpdating can be set to False prior to creating the checkboxes, and set back to True afterwards. Try something like this...

VBA Code:
Application.ScreenUpdating = False

With WdClothingForm
    For tblrow = 2 To .Rows.Count Step 1
        Set chk = .Parent.InlineShapes.AddOLEControl("Forms.CheckBox.1", .Cell(tblrow, 8).Range)
        With chk
            .Width = 15
            .Height = 21
            .OLEFormat.Object.Name = "ChkBx" & tblrow - 1
        End With
    Next tblrow
End With

Application.ScreenUpdating = True

Hope this helps!
 
Last edited:
Upvote 0
There's no need to do any selecting, nor is there any need to do any copying and pasting. These will make things much more inefficient. Also, in order to speed things up, ScreenUpdating can be set to False prior to creating the checkboxes, and set back to True afterwards. Try something like this...

VBA Code:
Application.ScreenUpdating = False

With WdClothingForm
    For tblrow = 2 To .Rows.Count Step 1
        Set chk = .Parent.InlineShapes.AddOLEControl("Forms.CheckBox.1", .Cell(tblrow, 8).Range)
        With chk
            .Width = 15
            .Height = 21
            .OLEFormat.Object.Name = "ChkBx" & tblrow - 1
        End With
    Next tblrow
End With

Application.ScreenUpdating = True

Hope this helps!
Hi Domenic,

Thank you so much for your reply. I did have Wapp.screenupdating (Wapp word application) set to false much earlier in the code.
The speed is the same as before. At least I now know it is probably the best I am going to achieve; and your code snippet is much neater.
 
Upvote 0
Yeah, even with only a relatively few rows, it seems rather slow.

Anyway, thanks for the feedback.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top