![]() |
|
|
|
#1
|
|||
|
|||
|
If the code is in the Normal template then it will already be trusted.
What does "when I open a document from the template it doesn't work" mean exactly? When I run your code: Code:
Sub ColourTable()
Dim objTable As Table
Dim iRowCounter As Integer
Dim iColumnCounter As Integer
Dim lngBadColor As Long
Dim lngGoodColor As Long
' Predefine colors
lngBadColor = RGB(255, 0, 0)
lngGoodColor = RGB(169, 208, 142)
' Loop through all tables in document
For Each objTable In ActiveDocument.Tables
For iRowCounter = 1 To objTable.Rows.count
For iColumnCounter = 1 To objTable.Columns.count
' Get Table cell
With objTable.Cell(iRowCounter, iColumnCounter)
If InStr(.Range.Text, "TO BE DONE") > 0 Then .Shading.BackgroundPatternColor = lngBadColor
If InStr(.Range.Text, "Yes") > 0 Then .Shading.BackgroundPatternColor = lngGoodColor
If InStr(.Range.Text, "N/A") > 0 Then .Shading.BackgroundPatternColor = lngGoodColor
If InStr(.Range.Text, "None") > 0 Then .Shading.BackgroundPatternColor = lngGoodColor
' If InStr(.Range.Text, "Very good") > 0 Then .Shading.BackgroundPatternColor = lngVeryGoodColor
' If InStr(.Range.Text, "Minor") > 0 Then .Shading.BackgroundPatternColor = lngGoodColor
End With
Next
Next
Next
End Sub
|
|
#2
|
|||
|
|||
|
Yeah, what you've shown me is how it's supposed to work (Like a visual checklist)
The template document is called 'Investigation Template'. When I open that actual document, the code works. (Opening the file from the actual file location) When I open a new document based on 'Investigation Template' - which will open as Document 2 (for example), then it doesn't work. (Opening the file using 'File' and 'New' in Word). Does that help explain? |
|
| Tags |
| run a macro, template form |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| referenceing/finding word from one documents into another documents and indicating their location | rok123 | Word VBA | 1 | 02-07-2016 04:50 PM |
| Microsoft Word 2013 Documents open as full version documents on two computers sporadically | Jaydenc-Fortress | Word | 2 | 08-07-2014 12:34 AM |
| Office 2010 Can't Open Or Save Documents in My Documents Folder | trippb | Office | 1 | 07-12-2013 07:29 AM |
update template in all documents
|
vangxbg | Word VBA | 1 | 02-25-2013 04:04 AM |
Attach a template to 1000+ documents
|
ohmzoned | Word | 1 | 02-04-2012 12:09 AM |