mercredi 21 septembre 2016

VBA checkboxes in Word

So i have a word document which has lots of pages, and sections which after each step have a an active x control check box.

At the end of the document there is a completion table which has the name of the sections and when the last check box for a certain section is ticket, it turns that part of the table green.

So for an example:

SECTION 1:

Text

(Checkbox 1)

moretext

(Checkbox 2)

evenmoretext

(Checkbox 3)

Completion list: Section 1

So what i want to be able to do is have some vba that will check to see if ALL of the checkboxes are ticked, and then make the section one part on the table at the end green.

I currently have it working so it turns it green but only when then last checkbox (3) is ticked.

Is there anyway to do this?

There is also another matter where, i have a button at the top of the document that hides a few of the sections through-out the document which when pressed ticks any boxes it is going to be hiding first. ( i use page breaks to show which parts i want to hide)

This is a problem however because the active x checkboxes do not hide, and so i have written some VBA which instead makes them super tiny, and then resizes them after its done.

Any help on either of these things would be much appreciated.

Here is the vba i have so far:

Private Sub DTSCheckBox_Click()

If (DTSCheckBox.Value = True And AdminCheckBox.Value = True) Then
    Section2Complete.Caption = "Complete": Section2Complete.BackColor = RGB(0, 255, 0): CheckAndAmmendBy.Caption = UpgradeTechnic.Text
Else
    Section2Complete.Caption = "Outstanding": Section2Complete.BackColor = RGB(255, 0, 0): CheckAndAmmendBy.Caption = ""
End If

End Sub

Private Sub V4ToV6Button_Click()

        ActiveDocument.Sections(2).Range.Font.Hidden = True: ActiveDocument.Sections(4).Range.Font.Hidden = True: ActiveDocument.Sections(6).Range.Font.Hidden = True: ActiveDocument.Sections(8).Range.Font.Hidden = True: Section15Complete.Caption = "": Section15Complete.BackColor = RGB(255, 255, 255): ActiveDocument.Tables(1).Rows(15).SetHeight 1, wdRowHeightExactly: SQLScriptCheckbox.Value = True: SQLScriptCheckbox.Height = 1: SQLScriptCheckbox.Width = 1: SQLScriptCheckbox.Enabled = False: RestoreEmailScriptCheckBox.Value = True: RestoreEmailScriptCheckBox.Height = 1: RestoreEmailScriptCheckBox.Width = 1: RestoreEmailScriptCheckBox.Enabled = False: SQLCleanScriptCheckBox.Value = True: SQLCleanScriptCheckBox.Height = 1: SQLCleanScriptCheckBox.Width = 1: SQLCleanScriptCheckBox.Enabled = False
        SandboxJobHasBeenSetUpCheckBox.Value = True: SandboxJobHasBeenSetUpCheckBox.Width = 1: SandboxJobHasBeenSetUpCheckBox.Height = 1: SandboxJobHasBeenSetUpCheckBox.Enabled = False

End Sub




Aucun commentaire:

Enregistrer un commentaire