Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-19-2016, 06:19 PM
wlcdo2 wlcdo2 is offline Reference Word Table Cell Using Offset? Windows 7 32bit Reference Word Table Cell Using Offset? Office 2013
Novice
Reference Word Table Cell Using Offset?
 
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
  #2  
Old 06-19-2016, 07:42 PM
macropod's Avatar
macropod macropod is offline Reference Word Table Cell Using Offset? Windows 7 64bit Reference Word Table Cell Using Offset? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,250
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Word has no offset function. Instead, in Word you could use code like:
Code:
Private Sub CheckBox1_Click()
Call ShadeCell(CheckBox1.Value)
End Sub
 
Sub ShadeCell(bVal As Boolean)
Application.ScreenUpdating = False
With Selection.Cells(1).Previous.Shading
  .BackgroundPatternColor = wdColorAutomatic
  If bVal = True Then
    .BackgroundPatternColor = wdColorYellow
  Else
    .BackgroundPatternColor = wdColorAutomatic
  End If
End With
Application.ScreenUpdating = True
End Sub
with each checkbox calling the ShadeCell macro as demonstrated above. Exactly why the code needs to call '.BackgroundPatternColor = wdColorAutomatic' before testing bVal isn't clear but, on my system, it only seems to shade the active cell without it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-19-2016, 08:53 PM
wlcdo2 wlcdo2 is offline Reference Word Table Cell Using Offset? Windows 7 32bit Reference Word Table Cell Using Offset? Office 2013
Novice
Reference Word Table Cell Using Offset?
 
Join Date: Jun 2016
Posts: 17
wlcdo2 is on a distinguished road
Default

Thank you so much Paul; Perfect!! Very much appreciated. I've got another conundrum that I might be asking about shortly; it involves taking the value from a UserForm and transferring it to a specific cell within a table. I'll see what I can do find before asking another question.
Thanks once again.
Regards Corin.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to reference more than one table in a Word doc scootermac315 Word VBA 5 06-22-2015 05:28 PM
Reference Word Table Cell Using Offset? Offset Table and Pivot Table ubns Excel 1 04-17-2015 12:28 AM
Reference Word Table Cell Using Offset? Assign the value of a cell as a cell reference of another cell in Excel 2010 - How to? bharathkumarst Excel 7 10-13-2014 10:25 AM
Reference Word Table Cell Using Offset? Syntax to use OFFSET() in a cell formula? dlowrey Excel 3 07-09-2013 09:15 AM
How do I reference a merged cell in a multi column & row table in MS Word ('03')? jihanemo Word Tables 0 03-18-2009 08:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:18 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2022 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft