Consulting

Results 1 to 2 of 2

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

  1. #1
    VBAX Regular
    Joined
    Feb 2017
    Location
    Hong Kong
    Posts
    33
    Location

    Question Excel VBA get Data from winword form ( Can't get some Checkbox value correctly )

    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).Checke d Then C02 = True ' 02 Injured whilst lifting or carrying
    If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(17).Checke d Then C03 = True ' 03 Slip, trip or fall on same Level
    If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(12).Checke d 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).Checke d 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).Checke d Then C13 = True ' 13 Contact with moving machinery or object being machined
    If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(11).Checke d 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).Checke d Then C16 = True ' 16 Exposure to explosion
    If ActiveDocument.SelectContentControlsByTitle("AccidentType").Item(14).Checke d 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

    ~~~//

    Sub-Form.jpg

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    This is essentially a duplicate of what you have asked in: http://www.vbaexpress.com/forum/show...ntrol-Checkbox
    Kindly don't post questions about the same issue in multiple threads. Thread closed. You may continue the discussion in your original thread.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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