View Single Post
 
Old 06-19-2016, 06:19 PM
wlcdo2 wlcdo2 is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Jun 2016
Posts: 17
wlcdo2 is on a distinguished road
Default Reference Word Table Cell Using Offset?

I have a Word 2013 document with a number of tables. One table contains say 18 columns and 13 rows; each even numbered column contains an ActiveX CheckBox that references the cell to the left. When the CheckBox is selected, I want to simply format the cell to the left. I've used some basic coding, but with the number of rows and columns, I then have to change the value for each CheckBox. My code per CheckBox is as follows:

Code:
Application.ScreenUpdating = False
    If cbHazChem.Value = True Then
        ActiveDocument.Tables(24).Cell(3, 1).Select
        Selection.Shading.BackgroundPatternColor = wdColorYellow
    Else
        ActiveDocument.Tables(24).Cell(3, 1).Select
        Selection.Shading.BackgroundPatternColor = wdColorAutomatic
    End If
Application.ScreenUpdating = False
I've used the Range.Offset property in Excel before and was wondering if there is something similar in Word VBA? i.e. so that I don't have to manually change the Cell reference for each and every CheckBox i.e. ...Cell(4,1)....Cell(5.1). I guess the code would need to know precisely where the Checkbox that was ticked is though, wouldn't it which might make the code for each CheckBox even longer?

Any thoughts?

Regards Corin.
Reply With Quote