PDA

View Full Version : Excel VBA get Data from winword form ( Can't get some Checkbox value correctly )



justuptou
05-23-2019, 06:49 PM
I create a coding from Excel VBA for reading winword form,
but the coding can't be worked a parts of checkbox as I preferred.
(may be the check boxes are in multi table but the coding is succeed to read in winword VBA),
For example for below,

Coding of PART 1 - Checkbox - All value (C01, C02..... and C17) as "True"

Coding of PART 2 - Checkbox - Correct to reading the value (bCheck_4)

could you tell me what is the problem is ?

//~~~

// Part 1 - Checkbox
' Type of Accident
With .Cell(8, 1).Tables(1)

If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(6).Checked Then C01 = True Else C01 = False ' 01 Trapped in or between objects
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(13).Checked Then C02 = True ' 02 Injured whilst lifting or carrying
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(17).Checked Then C03 = True ' 03 Slip, trip or fall on same Level
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(12).Checked Then C04 = True ' 04 Fall of person from height
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(8).Checked Then C05 = True ' 05 Striking against fixed or stationary object
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(7).Checked Then C06 = True ' 06 Striking against moving object
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(9).Checked Then C07 = True ' 07 Stepping on object
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(2).Checked Then C08 = True ' 08 Exposure to or contact with harmful substance
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(1).Checked Then C09 = True ' 09 Contact with electricity or electric discharge
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(15).Checked Then C10 = True ' 10 Trapped by collapsing or overturning Object
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(4).Checked Then C11 = True ' 11 Stuck by moving or falling object
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(5).Checked Then C12 = True ' 12 Stuck by moving Vehicle
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(16).Checked Then C13 = True ' 13 Contact with moving machinery or object being machined
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(11).Checked Then C14 = True ' 14 Drowning
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(3).Checked Then C15 = True ' 15 Exposure to fire
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(10).Checked Then C16 = True ' 16 Exposure to explosion
If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(14).Checked Then C17 = True ' 17 Others(please specify)

C51 = Trim(.Cell(5, 2).Range.Text) ' Falling Metres
C52 = Trim(.Cell(6, 2).Range.Text) ' Falling Metres
C53 = Trim(.Cell(6, 6).Range.Text) ' Others

End With

// Part 2 - Checkbox
' Hospitalized
If ActiveDocument.SelectContentControlsByTitle("Hospitalized").Item(1).Checked = True Then
bChecked_4 = True ' Stay at Hospital
ActiveDocument.SelectContentControlsByTitle("Hospitalized").Item(2).Checked = False
Else
bChecked_4 = False ' Stay at Hospital
ActiveDocument.SelectContentControlsByTitle("Hospitalized").Item(2).Checked = True
End If

~~~//

24277

macropod
05-23-2019, 10:06 PM
This is essentially a duplicate of what you have asked in: http://www.vbaexpress.com/forum/showthread.php?65161-Can-I-use-Excel-VBA-with-data-to-create-a-WinWord-form-(Consists-to-control-Checkbox
Kindly don't post questions about the same issue in multiple threads. Thread closed. You may continue the discussion in your original thread.