<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ShaunaKelly.com</title>
	<atom:link href="http://www.shaunakelly.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.shaunakelly.com</link>
	<description>Making the most of Word in your business</description>
	<lastBuildDate>Wed, 31 Aug 2011 13:43:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to create numbered headings or outline numbering in Word 2007 and Word 2010</title>
		<link>http://www.shaunakelly.com/word/numbering/numbering20072010.html</link>
		<comments>http://www.shaunakelly.com/word/numbering/numbering20072010.html#comments</comments>
		<pubDate>Wed, 31 Aug 2011 07:25:19 +0000</pubDate>
		<dc:creator>Shauna Kelly</dc:creator>
				<category><![CDATA[Numbering, headings, outlines]]></category>
		<category><![CDATA[Headings]]></category>
		<category><![CDATA[Keyboard shortcuts]]></category>
		<category><![CDATA[Outline view]]></category>

		<guid isPermaLink="false">http://localhost/STK.com/?p=1768</guid>
		<description><![CDATA[How to set up heading numbering in Word 2007 and Word 2010]]></description>
			<content:encoded><![CDATA[<p><em>How you set up numbered headings depends on <a href="index.php?p=1178"  title="Read 'What version of Word do I have?' on this site" >what version of Word you have</a>. This page is about setting up numbered headings in Word 2007 and Word 2010. If you have Word 2003 or an earlier version, see <a href="index.php?p=1749"  title="Read 'How to create numbered headings or outline numbering Word 2007 and Word 2010' on this site" >How to create numbered headings or outline numbering in Word 2003 and earlier versions</a>.</em></p>
<h2>Numbering run amok</h2>
<p>Word&#39;s paragraph numbering sometimes goes haywire. Just when you think you&#39;ve got it organized, the numbering starts doing silly things. If Word&#39;s paragraph numbering were a group of orchestral musicians, it might look like this:</p>
<div class="ImageInLine" >
<p><img src="wordimages/numbering/numbering2010/Geelong.jpg"  style="width: 425px; height: 295px;" /></p>
<p>Musicians run amok</p>
</div>
<h2>What&#39;s needed?</h2>
<div class="ImageFloatRight" >
<p><a href="http://qyo.org.au"  title="Link to the Queensland Youth Orchestra's web site" ><img src="wordimages/numbering/numbering2010/Curro.jpg"  style="width: 200px; height: 184px;" /></a></p>
<p>This man will get them into line!</p>
</div>
<p>What&#39;s needed is someone to get those mad horn players organized and co-ordinated. We don&#39;t need another player: we clearly have enough of those! What we need is a co-ordinator.</p>
<p>In an orchestra, the conductor co-ordinates. For Word&#39;s numbering, the mechanism we use to organize and co-ordinate paragraph numbering is a List Style. The List Style co-ordinates. It doesn&#39;t do the actual work of formatting text. We leave that to paragraph styles.</p>
<p>So, we need:</p>
<ul>
<li>a List Style as the co-ordinating mechanism for the numbering, and</li>
<li>a paragraph style for each heading level (Word allows, actually requires, 9 levels).</li>
</ul>
<div class="PopOut Tip"   style="display: none;display: none;">
<p>Understanding List Styles</p>
<p>A List Style has 9 levels. Each level can be linked to a paragraph style. And, each level stores information about how to number text to which that linked paragraph style has been applied.</p>
</div>
<p>A List Style actually does two things.</p>
<ul>
<li>A List Style creates a set or group of styles. Word comes with built-in paragraph styles named Heading 1, Heading 2, Heading 3. But there is no connection between them. They just happen to share similar names. A List Style &#39;groups&#39; those paragraph styles into some order. Only the List Style knows that Heading 1 is followed by Heading 2 and that it is followed by Heading 3. There are 9 levels in any List Style.</li>
<li>A List Style stores the information about how to number each level. That includes the format of the number ( &quot;1&quot; or &quot;a&quot; or &quot;i&quot;), whether the number is preceded by text (eg &quot;Chapter 1&quot; or &quot;Part A&quot;), whether the number includes previous levels&#39; numbers (eg paragraph 1.4.3), and the indents (the distance from margin to number and from number to text).</li>
</ul>
<h2>Set up your Heading paragraph styles</h2>
<p>There are good reasons for <a href="index.php?p=16"  title="'Why use Microsoft Word's built-in heading styles'" >using the built-in Heading styles</a>.</p>
<p>Before you begin the numbering, make sure your Heading styles are set up appropriately.</p>
<p><a href="index.php?p=1420"  title="How to modify a style in Word" >Modify</a> the Heading 1 style so that it is based on &quot;No style&quot;. Modify Heading 2 so it&#39;s based on Heading 1. Modify Heading 3 based on Heading 2. And so on. Not everyone does this, but I find it useful because of the way the formatting of Word&#39;s styles <a href="index.php?p=1485"  title="How the formatting of Word's styles cascade" >cascade</a>.</p>
<p>Now, modify the Paragraph settings of every Heading style so that the Left Indent is 0, and the Special indent is set to (none). Do this even if you want your headings to be indented from the left margin, and even if you want a hanging indent. Why? Because for outline-numbered styles, we will set the paragraph indent and the hanging indents (if any) when we set up the numbering.</p>
<h2>Create a list style</h2>
<p>To create your list style, on the Home tab, in the Paragraph group, click the Multilevel list menu (Figure 1).</p>
<div class="ImageInLine" >
<p><img alt="Choose the Define New List Style option from the Multilevel List menu"  src="wordimages/numbering/numbering2010/HomeTabNumberingButtons.png"  style="width: 415px; height: 213px;" /></p>
<p>Figure 1: Choose the Multilevel list menu</p>
</div>
<p>From the menu, choose <span class="Key" >Define New List Style</span> (Figure 2).</p>
<div class="ImageInLine" >
<p><img alt="Choose the Define New List Style option from the Multilevel List menu"  src="wordimages/numbering/numbering2010/DefineNewListStyle.png"  style="width: 353px; height: 506px;" /></p>
<p>Figure 2: On the Multilevel list menu, choose the Define New List Style option.</p>
</div>
<p>In the Define New List Style dialog (Figure 3), do (only) two things:</p>
<ol>
<li>Give your list style a name.<br/>
		Hint: Give it a <em>plural</em> name. That makes it clear that this is a list style that&#39;s controlling more than one paragraph style. And, give it a name directly related to the paragraph styles you&#39;re going to use. We&#39;re going to use paragraph styles Heading 1, Heading 2, Heading 3 etc. So <strong>I&nbsp;suggest that you name the list style as Headings</strong>.</li>
<li>On the Format menu, click Numbering.</li>
</ol>
<div class="ImageInLine" >
<p><img alt="In the Define New List Style dialog, give your style a name and then click Format and choose Numbering"  src="wordimages/numbering/numbering2010/DefineNewListStyleDialog.png"  style="width: 595px; height: 747px;" /></p>
<p>Figure 3: In the Define New List Style dialog, give your list style a name and then click Format > Numbering. Skip everything else in this dialog box. It&#39;s not for grown-ups.</p>
</div>
<p>We&#39;re now in the Modify Multilevel List dialog box (Figure 5). The list style is the co-ordinating mechanism for the whole &quot;set&quot; of paragraph styles we&#39;ll use. So we set up all levels of numbering in this one dialog box.</p>
<p>To set up the numbering:</p>
<ol>
<li>In the Modify multilevel list dialog, <strong>click the More button</strong>.</li>
<li><strong>Attach the Heading paragraph styles</strong> to the 9 levels in the list style. To do that:
<ol>
<li>In the &#39;Click level to modify&#39; list, select level 1. In the &#39;Link level to style&#39; box, choose Heading 1. That attaches paragraph style Heading 1 to level 1 of the list style.</li>
<li>
<p>In the &#39;Click level to modify&#39; list, select level 2 and attach style Heading 2. And attach Heading 3 to level 3, Heading 4 to level 4 and so on.</p>
</li>
</ol>
</li>
<li>Now we <strong>tell Word about the numbering itself for Level 1</strong>
<ol>
<li>In the &#39;Click level to modify&#39; list, click level 1.</li>
<li>Delete anything in the &#39;Enter formatting for number&quot; box.</li>
<li>If you want the numbering to start with some text (eg to number a paragraph as &quot;Chapter 1&quot; or &quot;Section 1&quot;) then enter the text including any space in the &#39;Enter formatting for number&#39; box. Leave the insertion point <em>after</em> your text.</li>
<li>From the Number style for this level list, choose the kind of numbering you want.</li>
</ol>
</li>
<li><strong>Set up numbering for levels 2 to 9</strong>.
<ol>
<li>In the &#39;Click level to modify&#39; list, choose Level 2.</li>
<li>Delete anything in the &#39;Enter formatting for number&quot; box.</li>
<li>If you want to include a previous level&#39;s numbering, then use the &#39;Include level number from&#39; box. If you want punctuation after each level, add it into the &#39;Enter formatting for number&#39; box as you go.
<p>For example, for Level 2, I might want the numbering to be &quot;1.1&quot;. That is, I want the Level 1 number and the Level 2 number. So, from the &#39;Include level number from&#39; box, I choose &#39;Level 1&#39;. Then I type a full stop (full point, period, whatever). Then I choose from the &#39;Number style for this level&#39; box.</p>
<p>You have to do each previous level separately. By the time you come to do Level 9, if you want paragraphs numbered 1.1.1.1.1.1.1.1.1, you need to add Level 1, Level 2, Level 3 etc, all the way to Level 8. This can get tedious, but hang in there!</p>
</li>
<li>From the Number style for this level list, choose the kind of numbering you want for the current level.</li>
<li>Repeat for each of levels 3 to 9. If you don&#39;t want numbering for a level, leave the &#39;Enter formatting for number&#39; box empty.</li>
</ol>
</li>
<li>Next, <span style="font-weight: bold;" >set up </span><strong>the indents</strong>: how far in from the left margin do you want the different levels to appear? The default indents are actually quite reasonable. If you prefer to change them, then you have two choices. The easy way is to click the &quot;Set for all levels&quot; button. You&#39;ll see the Set for All levels dialog (Figure 4).
<div class="ImageInLineNoBorder"  width="271px;" >
<p><img src="wordimages/bullets/BulletIndentsSetForAllLevels2010.png"  style="width: 271px; height: 160px;" /></p>
<p>Figure 4: Use the Set for All levels dialog to manage indents for your headings</p>
<p>&nbsp;</p>
</p></div>
<p>The hard way is to set the &#39;Aligned at&#39;, &#39;Text indent at&#39; and &#39;Add tab stop at&#39; boxes individually. Just remember that they&#39;re all measured from the left margin.</p>
</li>
<li>My finished settings look like Figure 5.
<div class="ImageInLineNoBorder"  style="width: 538px;" >
<p><img alt="The Modify Multilevel List dialog when it's finished"  src="wordimages/numbering/numbering2010/ModifyMultilevelList_Numbering_2010.png"  style="width: 538px; height: 472px;" /></p>
<p>Figure 5: The finished settings in the Modify Multilevel List dialog</p>
<p>&nbsp;</p>
</p></div>
</li>
<li><span class="Key" >OK</span>, <span class="Key" >OK </span>back to your document.</li>
</ol>
<h2>How to apply the Heading styles to your text</h2>
<p>So you have set up your List Style. But we don&#39;t ever <em>use</em> the List Style. Instead, we format paragraphs using the Heading 1, Heading 2 etc paragraph styles. Because you linked the heading paragraph styles to the List Style, the heading styles will now use the numbering you set up in the List Style.</p>
<div class="PopOut Tip"   style="display: none;display: none;">
<p>Applying numbering</p>
<p>The conductor doesn&#39;t produce any sound: musicians do that. And you won&#39;t find a part for the conductor in the score.</p>
<p>The list style doesn&#39;t format your text: paragraph styles do that. And you won&#39;t find the list style in the Styles pane.</p>
<p>Apply your paragraph styles to text. We don&#39;t ever actually <em>use</em> the list style.</p>
</div>
<h3>How to apply Heading 1 style to a paragraph</h3>
<p>To apply the numbering to one or more paragraphs in your document:</p>
<ol>
<li>click once within a paragraph, or select text from two or more paragraphs</li>
<li>on the Home tab, click the thumbnail for the Heading 1 style&nbsp; (or, for keyboard junkies, use Ctrl-Alt-1, which is the built-in keyboard shortcut for applying style Heading 1).</li>
</ol>
<h3>How to create a lower-level heading (or: how to demote a heading)</h3>
<div class="ImageFloatRight"  style="width: 281px;" >
<p><img alt="The Increase Indent button on the Word Home tab"  src="wordimages/numbering/bullets2007/IncreaseIndent2010.png"  style="width: 281px; height: 171px;" /></p>
<p>Figure 6: Use the Increase Indent button to demote a paragraph (ie indent it to the right)</p>
</div>
<p>You can create lower levels of headings by applying the paragraph styles Heading 2, Heading 3 etc. There are lots of ways to apply a paragraph style to your text. Here are three particularly relevant to headings:</p>
<ul>
<li>By default, the heading styles appear on the Quick Styles gallery as you need them. That is, once you&#39;ve used, say, style Heading 4, then Heading 5 will automagically appear on the Quick Styles gallery. Click in your paragraph, click the thumbnail for the style you want and presto! the paragraph is numbered.</li>
<li>Use the built-in keyboard shortcuts for the first three levels of headings: Alt-Ctrl-1, Alt-Ctrl-2, Alt-Ctrl-3.</li>
<li>Use the <span class="Key" >Increase Indent</span> button. It&#39;s on the Home tab, in the Paragraph group (Figure 6). And, to promote a paragraph (ie move it to the left), use the <span class="Key" >Decrease Indent</span> button. Or, for keyboard junkies use <span class="Key" >Shift-Alt-Right</span> arrow and <span class="Key" >Shift-Alt-Left</span> arrow.
<p>There are three important things to note here:</p>
</li>
</ul>
<ul style="margin-left: 40px;" >
<li>If you click in a paragraph in a Heading 1 style and click the Increase Indent button (or do <span class="Key" >Shift-Alt-Right</span> arrow), you&#39;re not applying some kind of nasty direct formatting. Word will apply style Heading 2 to your text. Click Increase Indent again, and Word will apply style Heading 3. And so on.
<p>That is, Word is applying the appropriate paragraph styles to your paragraphs.</p>
</li>
<li>The Increase Indent and Decrease Indent buttons (and Alt-Shift-Left and Alt-Shift-Right) only work in this special way because you attached your Heading paragraph styles to a list style. They don&#39;t work like this out-of-the-box.</li>
</ul>
<h2>How to edit your numbering scheme</h2>
<p>Your numbering scheme is stored in your Headings list style. It&#39;s not stored in the individual paragraph styles. Therefore:</p>
<ul>
<li><strong>Edit the individual paragraph styles</strong> if you want to change paragraph settings (eg space before or after) or the font of the text that follows the heading text (eg to make it big or pink or bold). To edit an individual paragraph style, see <a href="index.php?p=1420"  title="Read article on how to modify a style, on this site" >How to modify styles in Microsoft Word</a>.</li>
<li><strong>Edit the list style</strong> if you want to change the numbers, the position between number and text, the size of the number itself and so on. To edit your list style:
<ul>
<li>Click in a heading.</li>
<li>On the Home tab, in the Paragraph group, click the Multilevel list menu button (Figure 7)
<div class="ImageInLine" >
<p><img alt="Choose the Define New List Style option from the Multilevel List menu"  src="wordimages/numbering/numbering2010/HomeTabNumberingButtons.png"  style="width: 415px; height: 213px;" /></p>
<p>Figure 7: Choose the Multilevel list menu</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</p></div>
</li>
<li>You will see the Headings list style highlighted at the bottom of the menu.</li>
<li><span class="Key" >Right-click the thumbnail for the Headings list style</span> and choose <span class="Key" >Modify</span>. <span class="Key" >Format > Numbering</span> (Figure&nbsp;8). You can how change any or all of your numbering settings.
<div class="ImageInLine"  style="width: 525px;" >
<p><img src="wordimages/numbering/numbering2010/ModifyHeadingsListStyle.png"  style="width: 525px; height: 630px;" /></p>
<p>Figure 8: To edit your list style, hover over the thumbnails for the list styles to identify the one you need, then right-click and choose Modify.</p>
<p>&nbsp;</p>
</p></div>
</li>
</ul>
</li>
</ul>
<h2>Is all this really necessary? Can&#39;t I just use the List Library?</h2>
<p>If using the List Library on the Multilevel List menu (see Figure 2 or Figure 8 ) works for you, then go for it! For quick&#39;n&#39;dirty work, it may be just the thing.</p>
<p>For a corporate template that will be used by hundreds or thousands of users, it&#39;s probably not the best solution. For really big complicated documents, or documents where you have to cut and paste from one document to another a lot, then the List Library may let you down.</p>
<p>For more information, direct from Microsoft&#39;s Word development team, see <a class="External"  href="http://blogs.msdn.com/b/microsoft_office_word/archive/2007/03/08/the-many-levels-of-lists.aspx"  title="Read 'The many levels of lists' by Stuart Stuple of Microsoft's Word development team" >The Many Levels of Lists</a> and <a class="External"  href="http://blogs.msdn.com/b/microsoft_office_word/archive/2009/06/25/multilevel-lists-and-list-styles.aspx"  title="Read article about multilevel lists and List Styles direct from Microsoft's Word development team" >Multilevel Lists vs List Styles.</a></p>
<p>&nbsp;</p>
<p class="Acknowledgment" >Too good to be true?</p>
<p class="hMinor" >Related articles on other sites</p>
<p>All sounds too good to be true? It is<g>. When you&#39;ve finished getting your numbers just right, you might be interested to read some of the material MVPs have put together on numbering. Start at the <a href="http://www.word.mvps.org/"  title="The MS Word MVP FAQ site" >Microsoft Word MVP FAQ site</a>, click FAQ and then Numbering.</g></p>
<p>And, read from people in <a class="External"  href="http://blogs.msdn.com/b/microsoft_office_word/archive/tags/bullets+and+numbering/"  title="Read about bullets and numbering at Microsoft's Word team blog" >Microsoft&#39;s Word development team about numbering</a> especially Stuart Stuple&#39;s <a class="External"  href="http://blogs.msdn.com/b/microsoft_office_word/archive/2010/01/28/the-why-behind-our-styles-and-lists-designs.aspx" >The Why Behind Our Styles and Lists Designs</a>.</p>
<p class="hMinor" >Related articles on this site</p>
<p><a href="index.php?p=1758"  title="Read article 'How to create numbered headings or outline numbering in your Microsoft Word document' on this site" >How to create numbered headings or outline numbering in your Microsoft Word document. </a></p>
<p><a href="index.php?p=1968"  title="Read 'How to number headings and figures in Appendixes in Microsoft Word'" >How to number headings and figures in Appendixes in Microsoft Word</a></p>
<p>&nbsp;</p>
<p class="Acknowledgment" >Photo info</p>
<p>Photograph of horn players taken at <a class="External"  href="http://www.nationalmusiccamp.com.au/" >National Music Camp</a>, Geelong Grammar, January 1993. I have no recollection of why all the horn players were wearing silly hats, but National Music Camp has a fine tradition of encouraging innocent pranks and general merriment&#8212;as well as damned hard work&#8212;so it&#39;s not entirely surprising. What&#39;s more puzzing is why I kept the photo all these years!</p>
<p>John Curro, conductor of the <a class="External"  href="http://qyo.org.au" >Queensland Youth Orchestra</a> who taught me more than I&#39;ll ever know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunakelly.com/word/numbering/numbering20072010.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Background and foreground: Shading in paragraph styles</title>
		<link>http://www.shaunakelly.com/word/styles/shading-in-paragraph-styles.html</link>
		<comments>http://www.shaunakelly.com/word/styles/shading-in-paragraph-styles.html#comments</comments>
		<pubDate>Sun, 28 Aug 2011 01:24:47 +0000</pubDate>
		<dc:creator>Shauna Kelly</dc:creator>
				<category><![CDATA[Styles]]></category>
		<category><![CDATA[Backgrounds]]></category>
		<category><![CDATA[Paragraph styles]]></category>

		<guid isPermaLink="false">http://localhost/word/?p=7</guid>
		<description><![CDATA[For developers: The background colour in a paragraph style is controlled through the Shading object. It manages background and foreground colour and texture. The Word object model is straight-forward, but you need to choose the right texture as well as the background and foreground colours.]]></description>
			<content:encoded><![CDATA[<div class="PopOut QuickReference"   style="display: none;display: none;">
<p>To set background and foreground colours, do these steps in order:</p>
<ol>
<li>Set the <code>.BackgroundPatternColor</code>.</li>
<li>Set the <code>.Texture</code>. If you don&#39;t want a visible texture, set texture to <code>wdTextureNone</code>.</li>
<li>Set the <code>.ForegroundPatternColor</code>. If you don&#39;t want a visible foreground, set the colour to <code>wdColorAutomatic.</code>
<ol></ol>
</li>
</ol>
</div>
<p>In the Microsoft Word object model, background and foreground colours are controlled through a <code>Shading</code> object. This article explains how to manage shading for paragraph styles using the Microsoft Word object model.</p>
<h2>Shading basics</h2>
<p>Shading is controlled through a <code>.Shading</code> object. There are three main properties of a <code>.Shading</code> object:</p>
<ul>
<li><code>.BackgroundPatternColor</code></li>
<li><code>.ForegroundPatternColor</code></li>
<li><code>.Texture</code></li>
</ul>
<p>And, there are two properties of a paragraph style that return a <code>.Shading</code> object:</p>
<ul>
<li><code>Style.Shading</code></li>
<li><code>Style.ParagraphFormat.Shading</code></li>
</ul>
<p>These two objects appear to be the same thing. That is, if you set, say, <code>myStyle.Shading.ForegroundPatternColor = wdColorRed</code>, then Word automatically sets the <code>myStyle.ParagraphFormat.Shading.ForegroundPatternColor</code> to red. You can&#39;t set them independently.</p>
<p>The properties of a <code>.Shading</code> object mirror the user interface:</p>
<div class="ImageInLine" >
<p><img alt="Word Borders and Shading dialog"  src="wordimages/Styles/ParagraphStylesShading/ShadingDialog.png"  style="width: 591px; height: 404px;" /></p>
<p>The Shading tab of Word&#39;s Borders and Shading dialog. This example is from Word 2007 on Windows XP.</p>
</div>
<h2>Relationships between foreground colour, background colour and texture</h2>
<p>The tricky bits come when you try to work out how to manipulate the combination of foreground and background colours, and texture.</p>
<p>In the user interface, if you choose the Clear texture (<code>wdTextureNone</code> in the object model), then you only see the background colour. The UI won&#39;t let you set the foreground colour. If you choose the Solid texture (<code>wdTextureSolid</code> in the object model), then you only see the foreground colour.</p>
<p>In the object model, a newly-created paragraph style has:</p>
<ul>
<li><code>.BackgroundPatternColor = wdColorAutomatic</code></li>
<li><code>.ForegroundPatternColor = wdColorAutomatic</code></li>
<li><code>.Texture = wdTextureNone</code></li>
</ul>
<p>In the normal course of events, when you just want some coloured shading, set the <code>.BackgroundPatternColor</code> and ensure that the <code>.Texture</code> is <code>wdTextureNone</code>.</p>
<p class="Bug1Star" >However, if you set the <code>.ForegroundPatternColor </code>to any colour other than <code>wdColorAutomatic</code>, and you don&#39;t set the <code>.BackgroundPatternColor</code>, Word will change the <code>.Texture </code>from the default (<code>wdTextureNone</code>) to <code>wdTextureSolid</code>.</p>
<h2>How to manage background and foreground colours</h2>
<p>Based on these findings, the rules are:</p>
<h3><span>If you want a background with a plain, solid colour</span></h3>
<ol>
<li>Set the <code>.BackgroundPatternColor</code> to the colour of your choice.</li>
<li>Ensure that the <code>.Texture</code> is <code>wdTextureNone.</code></li>
<li>Ensure that the <code>.ForegroundPatternColor</code> is <code>wdColorAutomatic</code>.</li>
</ol>
<h3>If you want a pattern to display over the background color</h3>
<ol>
<li>Set the <code>.BackgroundPatternColor</code> to the colour of your choice.</li>
<li>Set the <code>.Texture</code> to something other than wdTextureNone.</li>
<li>Set the <code>.ForegroundPatternColor</code>.<br/>
		&nbsp;</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunakelly.com/word/styles/shading-in-paragraph-styles.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Borders in table styles</title>
		<link>http://www.shaunakelly.com/word/styles/borders-in-table-styles.html</link>
		<comments>http://www.shaunakelly.com/word/styles/borders-in-table-styles.html#comments</comments>
		<pubDate>Thu, 25 Aug 2011 13:15:58 +0000</pubDate>
		<dc:creator>Shauna Kelly</dc:creator>
				<category><![CDATA[Styles]]></category>
		<category><![CDATA[Borders]]></category>
		<category><![CDATA[Table styles]]></category>

		<guid isPermaLink="false">http://localhost/word/?p=18</guid>
		<description><![CDATA[What borders are available for table styles, how to control them, and how to avoid the bugs and inconsistencies in the Word object model.]]></description>
			<content:encoded><![CDATA[<p>Microsoft introduced table styles in Word 2002. There are 7 different objects that manage borders in a table style. My experience is that some of them work and some don&#39;t.</p>
<p>This page describes my experiences with borders in table styles. Your mileage, as they say, may vary.</p>
<h2>So what&#39;s the problem with borders and table styles?</h2>
<p>For basics of controlling borders in styles, see <a href="index.php?p=21"  title="Border basics for Developers" >Border basics for developers</a>. The issues for table styles are the same as those for non-table styles:</p>
<ul>
<li>A<code> .Borders</code> property can have 1, 4, 5 or 8 borders, some of which you can control, and some of which you can&#39;t.</li>
<li>Sometimes you can set the distance between the borders and the text, and sometimes you can&#39;t.</li>
<li>Sometimes can you set a shadow on the borders, and sometimes you can&#39;t.</li>
</ul>
<p>In addition, the built-in style Table Normal has its own rules, often different from the way any other table style, built-in or custom, behaves. In general, my experience is that it&#39;s best to leave style Table Normal alone. Avoid trying to read its properties, and if you do, litter your code with error catching. Certainly don&#39;t try to set the properties of Table Normal.</p>
<h2>Summary</h2>
<table border="1"  cellpadding="10"  cellspacing="0"  style="width: 527px; height: 90px;" >
<thead>
<tr>
<th scope="col" >Item in the Word object model</th>
<th scope="col" >Usefulness</th>
</tr>
</thead>
<tbody>
<tr>
<td>Style.Borders</td>
<td>Does not work. Word says &quot;That property is not available on that object&quot;</td>
</tr>
<tr>
<td>
<p>Style.Table.Borders</p>
</td>
<td>
<p>OK most of the time. Can&#39;t control diagonal borders, distance between border and text or shadows.</p>
</td>
</tr>
<tr>
<td>
<p>Style.ParagraphFormat.Borders</p>
</td>
<td>
<p>Dodgy. Significant display issues. Can&#39;t set distance between border and text. Can set shadows.</p>
</td>
</tr>
<tr>
<td>
<p>Style.Font.Borders</p>
</td>
<td>
<p>OK-ish. 1 border only. Can&#39;t control distance between border and text. Can set shadows.</p>
</td>
</tr>
<tr>
<td>
<p>Style.Table.Condition(n).Borders</p>
</td>
<td>
<p>OK-ish. Can&#39;t manage diagonal borders. Can&#39;t set distance between border and text. Can&#39;t use shadows.</p>
<p>May have unintended consequences (eg setting a border in the top row will turn off the display of the Total Row, Last Column and Banded Columns).</p>
</td>
</tr>
<tr>
<td>
<p>Style.Table.Condition(n).ParagraphFormat.Borders</p>
</td>
<td>
<p>Only 4 borders, not 5 as you&#39;d expect. Can&#39;t see the top border unless the <code>.TopPadding</code> is at least 9. Bottom border is unreliable. Can&#39;t set distance between border and text. Shadow works.</p>
</td>
</tr>
<tr>
<td>
<p>Style.Table.Condition(n).Font.Borders</p>
</td>
<td>
<p>Not recommended</p>
</td>
</tr>
</tbody>
</table>
<h2>How borders behave for different elements of table styles</h2>
<h3>Style.Borders</h3>
<p class="Bug1Star" >The Word Style object has a .Borders property. It doesn&#39;t work for a table style, and returns error &quot;That property is not available on that object&quot;.</p>
<h3>Style.Table.Borders</h3>
<p>This is the <code>.Borders</code> property of the table style&#39;s <code>.Table</code>. For example, <code>ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.Borders</code>.</p>
<p>There are 8 borders: top, right, bottom, left, horizontal, vertical and two diagonals.</p>
<p>Any border on the style&#39;s <code>.Table</code> will be overriden by, eg, <code>Style.Table.Condition(n).Border(m)</code>. So, for example, if the first column condition has a left border, then you won&#39;t see the whole-of-table border. That makes sense, because the specific is over-riding the general. This applies whether the condition&#39;s border is set before or after the <code>Style.Table.Borders </code>border.</p>
<h4>Top, right, bottom, left, horizontal and vertical borders</h4>
<p>These borders generally work as expected.</p>
<h4>Diagonal borders</h4>
<p class="Bug5Stars" >Diagonal borders are basically uncontrollable:</p>
<ul>
<li>Diagonal borders always display as <code>wdLineStyleSingle</code> no matter what line style you set.</li>
<li>You can&#39;t set a width on diagonal borders.</li>
<li>Diagonal borders always show as black, regardless of what colour you set.</li>
<li>You can&#39;t read the colour or width of a diagonal border. Both properties always return <code>wdUndefined</code>, even when the border is visible. Their default is <code>wdUndefined</code>, and they always report <code>wdUndefined</code>, so you can&#39;t rely on the reported value.</li>
</ul>
<p>Setting distance from top (eg <code>myStyle.Table.Borders.DistanceFromTop = 5</code>) never works. It does not produce an error, but it makes no difference, either.</p>
<p><code>.Shadow = True</code> never works. Word throws error 4198 &#39;Command Failed&#39;. And, when that happens, Word sets the first 6 borders (ie top, right, bottom, left, vertical and horizontal, but not diagonal) of the table to black, single line borders. So you can&#39;t just &#39;on error resume next&#39; your way past the <code>.Shadow</code> setting, because it has unintended consequences.</p>
<h3>Style.ParagraphFormat.Borders</h3>
<p>This property controls the borders of text within a table cell.</p>
<p>A Table style has a <code>.ParagraphFormat</code> property, which has a <code>.Borders</code> property. For example <code>ActiveDocument.Styles(&quot;MyTableStyle&quot;).ParagraphFormat.Borders</code>.</p>
<p>There are 5 borders: top, right, bottom, left plus horizontal borders. If you set the top border, it appears only on the first paragraph in the table cell. If you want a border on the top of every paragraph, use the horizontal border, which displays between paragraphs. As far as I can see, you can&#39;t set the Horizontal borders in the user interface. You can only do it through code.</p>
<p>Notes:</p>
<ul>
<li>
<p class="Bug3Stars" >You may not be able to see the borders at all unless you type some more text in the document. Even a print preview does not force the borders to display.</p>
</li>
<li>
<p class="Bug5Stars" >Generally, you can&#39;t see the top border if: (a) <code>.Shadow = False</code> and (b) the <code>Style.Table.TopPadding = 5</code>. Note that you may not be able to see the border in Print Layout view with other settings of <code>.TopPadding</code>, but you&#39;ll see the borders in Print Preview. But with <code>.TopPadding = 5</code>, you can&#39;t see the border in print preview, either. It may or may not print on paper. I&#39;ve seen other settings for <code>.TopPadding</code> that also go wrong. So these borders are a bit flaky.</p>
</li>
</ul>
<p>Distance from top (eg <code>myTableStyle.ParagraphFormat.Borders.DistanceFromTop = 20</code>) causes an error if the value is &lt; 0 or &gt;=31. Within that range, it does not appear to do anything.</p>
<p class="Bug1Star" ><code>.Shadow</code> works, but expect some display artefacts that don&#39;t print.</p>
<h3>Style.Font.Borders</h3>
<p>In the object model this is <code>Style.Font.Borders</code></p>
<p>There is only one border.</p>
<p class="Bug1Star" >Trying to set the distance between border and text (eg <code>myStyle.Font.Borders.DistanceFromTop = 10</code>) never works. It always returns error 5891: &quot;That property is not available on that object.&quot;</p>
<p>The <code>.Shadow</code> property works as expected.</p>
<h3>Style.Table.Condition(<em>n</em>).Borders</h3>
<p>In the object model, this is <code>Style.Condition(<i>n</i>).Borders</code>. A table style has 12 conditions (first column, last row, top right cell etc). <code>myStyle.Condition(1)</code> returns a <code>ConditionalStyle</code> object, and it has a <code>.Borders</code> property.</p>
<p>There are 8 borders: top, right, bottom, left, horizontal, vertical and two diagonals.</p>
<h4>Top, right, bottom, left, horizontal and vertical borders</h4>
<p>These work more-or-less as expected with three exceptions:</p>
<ul>
<li>
<p class="Bug3Stars" >The Distances between border and text do not cause an error if the value is &gt;=0 and &lt;32, but does not appear to do anything, either. They cause an error if value is &lt;0 or &gt;=32.</p>
</li>
<li>
<p class="Bug3Stars" >You can&#39;t set the <code>.Shadow</code> property. If you try to access this property, Word throws error 4198 &#39;Command failed&#39;.</p>
</li>
<li>
<p class="Bug3Stars" >Setting a border may have unintended consequences. For example, if the table in the document has been set to show the Total Row, Last Column and Banded Columns, and you set a border on the Top Row, then table will lose its Total Row, Last Column and Banded Column setting. So if you&#39;re going to set borders on a style in an existing document, you need to read these settings (for each table to which the style has been applied), store them, modify the style, apply it, then re-apply the individual table settings.</p>
</li>
</ul>
<h4>Diagonal borders</h4>
<p class="Bug5Stars" >Diagonal borders are basically uncontrollable.</p>
<ul>
<li>Diagonal borders always display as <code>wdLineStyleSingle</code> regardless of what line style you set.</li>
<li>You can&#39;t set a width on diagonal borders.</li>
<li>Diagonal borders always show as black, regardless of what colour you set.</li>
<li>You can&#39;t read the colour or width of a diagonal border. Both properties always return <code>wdUndefined</code>, even when the border is in plain sight. Their default is <code>wdUndefined</code>, and they always report <code>wdUndefined</code>, so you can&#39;t really manipulate diagonal borders in any way.</li>
</ul>
<h3>Style.Table.Condition(<em>n</em>).ParagraphFormat.Borders</h3>
<p>In the object model this is <code>Style.Condition(<em>n</em>).ParagraphFormat.Borders</code></p>
<p>There are 4 borders. Yes, 4. The <code>Style.ParagraphFormat.Borders</code> property has 5 borders, but <code>Style.Condition(<em>n</em>).ParagraphFormat.Borders</code> only has 4. I&#39;ve no idea why.</p>
<p>Notes:</p>
<ul>
<li>These borders over-ride the <code>Style.ParagraphFormat.Borders</code> setting for the particular border. That makes sense to me, because the specific is over-riding the general.</li>
<li>In early releases of Word 2007, the <code>Top </code>border wasn&#39;t visible unless the <code>.Condition(n).TopPadding</code> was at least 9. This is no longer a problem with Word 2007 Service Pack 2 and it works in Word 2010.</li>
<li>In early releases of Word 2007, the <code>Bottom </code>border was unreliable unless the <code>.Condition(n).BottomPadding</code> was less than 9. This is no longer a problem with Word 2007 Service Pack 2 and it works in Word 2010.</li>
</ul>
<p class="Bug3Stars" >The Distances between border and text do not cause an error if the value is &gt;=0 and &lt;32, but these properties do not appear to do anything, either. They cause an error if value is &lt;0 or &gt;=32.</p>
<p>The <code>.Shadow</code> works as expected.</p>
<h3>Style.Table.Condition(<em>n</em>).Font.Borders</h3>
<h4>In Word 2003</h4>
<p class="Bug5Stars" >Avoid this .Borders property.</p>
<p>We can&#39;t control these borders in code:</p>
<ul>
<li>These borders will be over-ridden by the <code>Style.Font</code> border. That doesn&#39;t make sense, because we would expect the specific to over-ride the general. Here, the reverse is true.</li>
<li>You can set a <code>.LineStyle</code>, but Word will ignore your setting. If you interrogate the property, Word seems to report <code>.LineStyle = 0</code> or <code>.LineStyle = wdUndefined</code> even when there is a line I can see.</li>
<li>You can&#39;t ever set <code>.LineWidth</code>: Word throws an error every time.</li>
<li>You can set a border <code>.Color</code>, but if you also set <code>.Shadow</code> to True, Word will ignore the colour and set the borders to Black, assuming no Style.Font.Borders settings.</li>
<li>Borders whose <code>.Color</code> is undefined sometimes return the number &minus;399507165 instead of 9999999 (the normal <code>Word.wdUndefined</code> constant). This number appears sporadically as the return value of a table style&#39;s <code>.Table.Condition(<em>x</em>).Font.Borders(1).Color</code>, but only if we&#39;re barging through the code, and not if we&#39;re using F8 to step through the code line by line. I have only seen it appear on some Conditions: last row, first column, last column, odd and even rows, even columns, top right cell and bottom right cell. I have not seen it appear on the other Conditions.</li>
<li>Even if you do set the colour, and leave <code>.Shadow = False</code>, Word will not return the correct colour of the border.</li>
</ul>
<p>These borders are badly behaved. For example, I used the user interface to set a border on the <code>.Font</code> of the first row (<code>.Condition(0)</code>). I could see the border. I then interrogated it in the Immediate pane in the VBE:</p>
<p>How can this happen?</p>
<pre>? ActiveDocument.Styles(&quot;Shauna&quot;).Table.Condition(0).Font.Borders(1).LineStyle
0
Set brdr = ActiveDocument.Styles(&quot;Shauna&quot;).Table.Condition(0).Font.Borders(1)
? brdr.LineStyle
9999999</pre>
<p>The display seems to come and go. The same code will sometimes display a border and sometimes not. That might just be a display or memory issue, but testing suggests otherwise. It may have something to do with the presence, or absence, of a border around the table as a whole, If the table has a border, you can&#39;t see the <code>.Condition(x).Font.Borders</code>.</p>
<p><code>Style.Table.Condition(0)</code> (condition 0 is the top row) is flakier than the rest. You rarely see the effect of the border in the top row.</p>
<p>Distances between text and border (eg <code>.DistanceFromTop = 5</code>)&nbsp; never works. You always get error 5891 &#39;That property is not available on that object&#39;.</p>
<h4>In Word 2007 and Word 2010</h4>
<p class="Bug5Stars" >Avoid this Borders property. It produces no borders, and will crash Word 2007 in a trice.</p>
<p class="Bug3Stars" >Setting the <code>.Borders(1).LineStyle</code> property or <code>.Borders(1).Color</code> property has no visible effect.</p>
<p class="Bug5Stars" >Setting the <code>.LineWidth</code> causes error 5843. In Word 2007, if you re-run the line of code with the error, Word may crash. To demonstrate, close and re-open Word, then run the following VBA code:</p>
<pre>Sub HowToCrashWord2007()
Dim doc As Word.Document
Dim sty As Word.Style

    Set doc = Documents.Add
    Set sty = doc.Styles.Add(Name:=&quot;ATableStyle&quot;, Type:=wdStyleTypeTable)

    With sty.Table.Condition(wdLastRow).Font.Borders(1)

        On Error Resume Next
        .LineWidth = wdLineWidth025pt

        &#39;Following line causes Word to crash
        .LineWidth = wdLineWidth025pt

    End With
End Sub</pre>
<p>In the original version of Word 2007, setting the <code>.Shadow</code> caused no error. In Word 2007 with SP2, attempting to set the <code>.Shadow</code> property causes error 4198. There&#39;s a nice case for testing our code against service packs!</p>
<p class="Bug3Stars" >Finally, we cannot read the property values of these borders<code>. .LineStyle</code> and <code>.LineWidth</code> always return <code>wdUndefined</code>. <code>.Colour</code> always returns 0. And <code>.Borders.Shadow</code> always returns True even though there is patently no shadow since no border is displayed.</p>
<p class="RelatedPages" >Related pages</p>
<ul>
<li><a href="index.php?p=21"  title="Border basics for Developers" >Border basics for Developers</a></li>
<li><a href="index.php?p=15"  title="Borders in character and paragraph styles" >Borders in character and paragraph styles</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunakelly.com/word/styles/borders-in-table-styles.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>4 ways to control page breaks within tables and table styles (for developers)</title>
		<link>http://www.shaunakelly.com/word/styles/page-breaks-in-tables.html</link>
		<comments>http://www.shaunakelly.com/word/styles/page-breaks-in-tables.html#comments</comments>
		<pubDate>Thu, 25 Aug 2011 11:30:01 +0000</pubDate>
		<dc:creator>Shauna Kelly</dc:creator>
				<category><![CDATA[Styles]]></category>
		<category><![CDATA[Captions]]></category>
		<category><![CDATA[Page breaks]]></category>
		<category><![CDATA[Pagination]]></category>
		<category><![CDATA[Table styles]]></category>

		<guid isPermaLink="false">http://localhost/word/?p=13</guid>
		<description><![CDATA[For developers: How to prevent a whole table, or just one or more rows, from breaking across a page. The Microsoft Word object model has 4 ways to manage, or prevent, tables from breaking across a page. Some of them work.]]></description>
			<content:encoded><![CDATA[<div class="PopOut QuickReference"   style="display: none;display: none;">
<p>Controlling page breaks in tables and table styles</p>
<p>Style.Table _<br/>
		.AllowBreakAcrossPage controls page breaks within all rows.</p>
<p>Table.Rows(<em>n</em>) _<br/>
		.AllowBreakAcrossPages controls page breaks within one or more rows.</p>
<p>Style.Table.AllowPageBreaks doesn&#39;t work.</p>
<p>.KeepWithNext sometimes keeps this paragraph on the same page as the next paragraph.</p>
</div>
<p>The Microsoft Word object model has four settings that control page breaks in tables and table styles:</p>
<ul>
<li>In a table style: <code>.AllowBreakAcrossPage</code></li>
<li>In a table: <code>.AllowBreakAcrossPages</code></li>
<li>In a table or table style: <code>.AllowPageBreaks</code></li>
<li>In a various places: <code>.KeepWithNext</code></li>
</ul>
<p>This page describes my observations about how these four settings work.</p>
<h2>In a table style: prevent or allow page breaks within rows (.AllowBreakAcrossPage )</h2>
<h5>What it does</h5>
<p>The <code>.AllowBreakAcrossPage</code> property applies to the Table of a table style. It controls the behaviour of individual rows, not the whole table. It determines whether the individual&nbsp;rows in a table may break across a page. But this is a property of the table style, not individual rows. So it applies to all rows in the table.</p>
<p>As far as I can see, there is no way to set this property from the user interface. You can only do it in code. However, in the user interface, you can override the setting for one individual row in a table to which this table style has been applied.</p>
<p>This is actually a very useful feature. In most tables I create, I don&#39;t want any rows to break across a page. Setting this property on the table style tells Word to do just what I want. And I can use the user interface to allow an individual row to break across a page if I need to.</p>
<p>As far as I can see, you can&#39;t use this property to define a table style such that some rows will break and others won&#39;t.&nbsp;But we can achieve the same thing using <code>.KeepWithNext</code>. See <a href="http://www.shaunakelly.com/feed#KeepWithNext"  title="See 'KeepWithNext', below" >below</a>.</p>
<h5>Default value</h5>
<p class="Bug1Star" >If I create a new table style, I observe that rows break across the page. So it seems like the default for <code>.AllowBreakAcrossPage</code> is True. The documentation says that this property returns a Long (not a Boolean), and that the default value is <code>True</code>. That sounds right, but it isn&#39;t. In Word-land, <code>True</code> is -1. But a newly-created style returns a value of 1 (not -1) for this property.</p>
<h5>Reading the property</h5>
<p>For a newly-created style, the default value is 1. Here is some sample VBA code from the immediate window:</p>
<pre>?ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.AllowBreakAcrossPage = True &#39; returns False
?ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.AllowBreakAcrossPage = False &#39; returns False</pre>
<p class="Bug3Stars" >Subsequently interrogating the value of <code>.AllowBreakAcrossPage</code> is also tricky. If I set the value to <code>.True</code>, the return value is 1 (which is not what you&#39;d expect), and Word denies that the value is <code>.True</code>. If I set the value to <code>.False</code>, the return value is 0 (which is kind of what you&#39;d expect) and Word acknowledges that the value is <code>.False</code>.</p>
<h5>Setting the property</h5>
<p>This works quite reliably:</p>
<pre> ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.AllowBreakAcrossPage = True</pre>
<h5>How to use this property</h5>
<ul>
<li>We can set the value reliably using&nbsp;<code>True</code> or&nbsp;<code>False</code> or 1 (&quot;true&quot;) or 0 (<code>False</code>).</li>
<li>To read the property value,&nbsp;we must assume that the&nbsp;only valid values are 1 (ie &quot;true&quot;) and 0 (<code>False</code>).</li>
</ul>
<p>As far as I can see, there is no way to set this property in the user interface.</p>
<h2>In a table: prevent or allow page breaks within specified rows&nbsp; (.AllowBreakAcrossPages)</h2>
<h5>What it does</h5>
<p>This property applies to a real, live table. It does not apply to a table style.</p>
<p><code>Table.Rows.AllowBreakAcrossPages</code> or <code>Table.Rows(n).AllowBreakAcrossPages</code> applies to an individual <code>Row </code>or all the <code>.Rows</code> of a table. It determines whether the row(s) may break across a page. This is the setting controlled in the user interface in the Table Properties dialog box, on the Row tab.</p>
<h5>Setting the property</h5>
<p>This property works quite reliably. For example:</p>
<pre>ActiveDocument.Tables(1).Rows(2).AllowBreakAcrossPages = False</pre>
<p>Note that individual rows retain the value of their <code>.AllowBreakAcrossPages</code> property, even if you change the underlying table style&#39;s <code>.Table.AllowBreakAcrossPage</code> property.&nbsp;</p>
<h5>Reading the property</h5>
<p>This property&nbsp;reliably returns True or False, just as you&#39;d expect.</p>
<h2>In a table or a table style:&nbsp;keep the whole table on one page&nbsp;(.AllowPageBreaks)</h2>
<p class="Bug5Stars" >This property does not work, and is effectively unusable.</p>
<h5>What it does</h5>
<p>This property applies to a table or a table style using <code>Table.AllowPageBreaks </code><em>or </em><code>Style.Table.AllowPageBreaks</code>.</p>
<p>It is <em><strong>supposed</strong></em> to work like this:</p>
<ul>
<li>If, given paper size, margins, fonts and so on,&nbsp;the whole table could fit on one page, and this property is True, then Word will pop the whole table over to the next page, and keep the whole table on one page.</li>
<li>If the whole table could fit on one page, and this property is False, then Word will split the table across two pages, with rows breaking according to the <code>.AllowBreakAcrossPage</code> and <code>.AllowBreakAcrossPages</code> settings.</li>
<li>If the table would not fit on one page, then Word will, not unreasonably, split the table across two or more pages regardless of the setting of .AllowPageBreaks.</li>
</ul>
<p>As far as I can see, you can only set this property in code. There is no way to set this property from the user interface. For the classic workaround in the user interface, see <a class="External"  href="http://word.mvps.org/FAQs/TblsFldsFms/KeepTableOn1Page.htm"  title="Read how to prevent a table from breaking across a page at the Word MVPs site" >Keeping a table together on one page.</a></p>
<h5>Default value</h5>
<p>Microsoft&#39;s object model documentation says that this is a Boolean. And indeed, if you query the property on a newly-created table style or table, Word will tell you that the value is <code>True</code>. But it isn&#39;t. The default value is actually 1, not <code>True</code>.</p>
<h5>Setting the property</h5>
<p>You can set the property in the normal way:</p>
<pre>ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.AllowPageBreaks = True</pre>
<p>But, this&nbsp;property&nbsp;doesn&#39;t work. That is, the table will not be kept on one page.</p>
<ul>
<li class="Bug5Stars" >In Word 2003, it will appear to work, but once you save the file and re-open it, it stops working.</li>
<li>In Word 2007, it does not appear to do anything.</li>
<li>In Word 2010, it does not appear to do anything. In Word 2010, Microsoft&#39;s object model help says that the AllowPageBreaks property is &#39;Hidden&#39; and that &#39;Hidden&#39; means &quot;The member has been deprecated and is not recommended for use in code.&quot;</li>
</ul>
<h5>Reading the property</h5>
<p>If you set the value to <code>True</code>, Word will then deny that you have so set it. The following, from the Immediate pane in the VBE, is clearly crazy:</p>
<pre>ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.AllowPageBreaks = True
?ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.AllowPageBreaks
True
?ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.AllowPageBreaks = True
False</pre>
<p>When Word reports that the value is <code>True</code>, the value is actually 1.</p>
<p>If you set the value to <code>False</code>, then Word behaves rather better:</p>
<pre>ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.AllowPageBreaks = False
?ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.AllowPageBreaks
False
?ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.AllowPageBreaks = False
True</pre>
<h5>How to use this property, given the bugs</h5>
<p>We can&#39;t use this property because it doesn&#39;t work.</p>
<h2><a name="KeepWithNext" ></a>.KeepWithNext</h2>
<p>&quot;Keep with next&quot; means &quot;keep this paragraph on the same page as the next paragraph&quot;.</p>
<p>The <code>.KeepWithNext</code> property applies to the <code>.Paragraphs</code> collection, a <code>.Paragraph</code> object and the <code>.ParagraphFormat</code> object.</p>
<p>Thus, it can be applied to one or more real paragraphs (using the <code>.Paragraphs</code> collection or a <code>.Paragraph</code> object) or to a paragraph or table style (using the style&#39;s <code>.ParagraphFormat</code> property).</p>
<p><code>.KeepWithNext</code> is used extensively in defining paragraph styles. By default, the heading styles have <code>.KeepWithNext = True</code> so as to prevent a heading at the bottom of the page, and its subsequent text at the top of the following page.</p>
<p>In tables, <code>.KeepWithNext</code> works a little differently. If any paragraph in a row of a table is marked <code>KeepWithNext = True</code>, then that row will always appear on the same page as the first paragraph in the following row. If that following row is marked so as not to break across a page, then the <code>KeepWithNext</code> setting has the effect of keeping that row on the same page as the whole of the following row.</p>
<p>In theory, we can set a table style&#39;s <code>.ParagraphFormat</code> to <code>KeepWithNext. </code>For example:</p>
<pre style="margin-left: 40px;" >ActiveDocument.Styles(&quot;MyTableStyle&quot;).ParagraphFormat.KeepWithNext = True
</pre>
<p class="Bug1Star" >But I can&#39;t see any effect of doing this. It doesn&#39;t seem to work at all.</p>
<p>But <code>.KeepWithNext</code> does have interesting, if inconsistent, effects when applied to just part of a table style using one of the style&#39;s <code>.Condition</code>s.</p>
<table border="1"  cellpadding="0"  cellspacing="0"  style="height: 86px;" >
<tbody>
<tr>
<td>
<p>Table style condition</p>
</td>
<td>
<p>Example (assuming <code>sty </code>is a Word table style)</p>
</td>
<td>
<p>Effect</p>
</td>
</tr>
<tr>
<td>
<p>First row</p>
</td>
<td>
<pre>sty.Table.Condition(wdFirstRow) _
.ParagraphFormat.KeepWithNext = True</pre>
</td>
<td>
<p>The first row will be displayed on the same page as the first paragraph of the second row</p>
</td>
</tr>
<tr>
<td>
<p>Last row</p>
</td>
<td>
<pre>sty.Table.Condition(wdLastRow) _
.ParagraphFormat.KeepWithNext = True</pre>
</td>
<td>
<p class="Bug1Star" >Doesn&#39;t seem to do anything. And what a pity that is! If it worked, we could use it to keep the last row of a table on the same page as its following caption.</p>
</td>
</tr>
<tr>
<td>
<p>First column</p>
</td>
<td>
<pre>sty.Table.Condition(wdFirstColumn) _
.ParagraphFormat.KeepWithNext = True</pre>
</td>
<td>
<p>Word will (attempt to) keep all rows on the same page as the following paragraph.<br/>
					In a small table, this has the effect of keeping the whole table <em>and the paragraph immediately following the table</em> on one page. If the table is too large to fit on one page, then inevitably the table will spill over onto second and if necessary subsequent pages. This has several consequences:</p>
<ul>
<li>If the paragraph following the table is a caption, this has the delicious side effect of keeping the table with its caption (unless you&#39;re in the unhappy position where the table itself would fit on one page, but the table plus its caption is too tall; in that case, the caption will be left alone on the second page).</li>
<li>If the paragraph following the table is not a caption, then you may see awkward pagination as Word tries to keep too much together on one page.</li>
</ul>
</td>
</tr>
<tr>
<td>
<p>Top left cell</p>
</td>
<td>
<pre>sty.Table.Condition(wdNWCell) _
.ParagraphFormat.KeepWithNext = True</pre>
</td>
<td>
<p>The first row will be displayed on the same page as the first paragraph of the second row. That is, this has the same effect as setting KeepWithNext on the first row.</p>
</td>
</tr>
<tr>
<td>
<p>Top right cell</p>
</td>
<td>
<pre>sty.Table.Condition(wdNECell) _
.ParagraphFormat.KeepWithNext = True</pre>
</td>
<td>
<p class="Bug1Star" >No apparent effect.</p>
</td>
</tr>
<tr>
<td>Bottom left cell</td>
<td>
<pre>sty.Table.Condition(wdSWCell) _
.ParagraphFormat.KeepWithNext = True</pre>
</td>
<td>
<p class="Bug1Star" >No apparent effect.</p>
</td>
</tr>
<tr>
<td>Bottom right cell</td>
<td>
<pre>sty.Table.Condition(wdSECell) _
.ParagraphFormat.KeepWithNext = True</pre>
</td>
<td>
<p class="Bug1Star" >No apparent effect.</p>
</td>
</tr>
<tr>
<td>Column and row banding</td>
<td>
<pre>sty.Table.Condition(wdEvenRowBanding) _
.ParagraphFormat.KeepWithNext = True

sty.Table.Condition(wdEvenColumnBanding) _
.ParagraphFormat.KeepWithNext = True

sty.Table.Condition(wdOddRowBanding) _
.ParagraphFormat.KeepWithNext = True

sty.Table.Condition(wdOddColumnBanding) _
.ParagraphFormat.KeepWithNext = True</pre>
</td>
<td>
<p class="Bug1Star" >No apparent effect.</p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunakelly.com/word/styles/page-breaks-in-tables.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Word reports the .BaseStyle of styles inaccurately</title>
		<link>http://www.shaunakelly.com/word/styles/word-reports-the-basestyle-of-styles-inaccurately.html</link>
		<comments>http://www.shaunakelly.com/word/styles/word-reports-the-basestyle-of-styles-inaccurately.html#comments</comments>
		<pubDate>Thu, 25 Aug 2011 11:00:20 +0000</pubDate>
		<dc:creator>Shauna Kelly</dc:creator>
				<category><![CDATA[Styles]]></category>

		<guid isPermaLink="false">http://localhost/STK.com/?p=4430</guid>
		<description><![CDATA[The problem Word styles cascade. Out of the box, a few styles have no parent, but most are based on another style. In the object model, this is controlled through the .BaseStyle property. One of the rules is that a style can only be based on another style of the same type. So, a Character [...]]]></description>
			<content:encoded><![CDATA[<h2>The problem</h2>
<p>Word styles <a href="word/styles/howstylescascade.html" >cascade</a>. Out of the box, a few styles have no parent, but most are based on another style. In the object model, this is controlled through the <code>.BaseStyle</code> property.</p>
<p>One of the rules is that a style can only be based on another style of the same type. So, a Character style can only be based on another Character style. A Table style can only be based on another Table style. And so on.</p>
<p>Interrogating the <code>.BaseStyle</code> of a Style routinely returns nonsense. Open a document and try something like this:</p>
<pre>Sub TestBaseStyles()

Dim sty As Word.Style

    For Each sty In ActiveDocument.Styles
        &#39;In a clean document, this produces nonsense
        Debug.Print sty.NameLocal, sty.BaseStyle
    Next sty

End Sub
</pre>
<p class="Bug3Stars" >Unless your <code>Style</code> object has been &#39;primed&#39; in some way, reading the <code>.BaseStyle</code> property produces unmitigated nonsense:</p>
<ul>
<li>Word 2003 reports that most styles are based on Normal style. Clearly character styles, table styles and list styles can&#39;t be based on Normal, since it&#39;s a paragraph style.</li>
<li>Word 2007 and Word 2010 seem to report a random style as the <code>.BaseStyle</code>. Table styles might tell you they&#39;re based on character styles. Character styles might tell you they&#39;re based on paragraph styles.</li>
</ul>
<h2>Workaround</h2>
<p>The best way I&#39;ve found to work around this is to read the <code>.Description</code> property before reading the <code>.BaseStyle</code> property. This somehow &#39;primes&#39; the Style object and thereafter it will report the <code>.BaseStyle</code> accurately.</p>
<p>So something like this works perfectly well:</p>
<pre>Sub TestBaseStyles()

Dim sty As Word.Style

    For Each sty In ActiveDocument.Styles
        Debug.Print sty.NameLocal, sty.Description, sty.BaseStyle
    Next sty

End Sub</pre>
<p>You don&#39;t have to output the <code>.Description</code> in any way. Just reading it and assigning to a variable will do. Something like this:</p>
<pre>Sub DoSomethingWithMyStyle()

Dim sty As Word.Style
Dim sDescription as String

    For Each sty In ActiveDocument.Styles
        &#39;&quot;Prime&quot; the style
        sDescription = sty.Description

        &#39;Now we can read the .BaseStyle
        MsgBox sty.BaseStyle
    Next sty

End Sub</pre>
<p>There are some other properties of a style that will coerce a style into reporting the correct <code>.BaseStyle</code>. That&#39;s why this problem does not appear very often: your code may already have read one of the properties that settle the style down. Reading the <code>.Linked</code> property of a paragraph style, for example, is enough to force Word to report the <code>.BaseStyle</code> accurately.</p>
<p>The advantage of using the <code>.Description</code> property is that it appears to be innocuous and applies to every style type, so it&#39;s easy to get into the habit of reading the <code>.Description</code> before reading the <code>.BaseStyle</code>.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunakelly.com/word/styles/word-reports-the-basestyle-of-styles-inaccurately.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error 5848 &#8220;The style definition is empty&#8221;, or, why are there two Normal styles in my document?</title>
		<link>http://www.shaunakelly.com/word/styles/error-5848-style-definition-is-empty.html</link>
		<comments>http://www.shaunakelly.com/word/styles/error-5848-style-definition-is-empty.html#comments</comments>
		<pubDate>Mon, 15 Aug 2011 13:29:40 +0000</pubDate>
		<dc:creator>Shauna Kelly</dc:creator>
				<category><![CDATA[Styles]]></category>
		<category><![CDATA[Paragraph styles]]></category>

		<guid isPermaLink="false">http://localhost/STK.com/?p=4999</guid>
		<description><![CDATA[What causes this error? I can&#39;t find any reference from Microsoft to the cause of error 5848 &#34;The style definition is empty.&#34;. But I can identify at least one way in which this error occurs. This only seems to go wrong in Word 2010, both RTM and SP-1. The Style object in Word has an [...]]]></description>
			<content:encoded><![CDATA[<h2>What causes this error?</h2>
<p>I can&#39;t find any reference from Microsoft to the cause of error 5848 &quot;The style definition is empty.&quot;.</p>
<p>But I can identify at least one way in which this error occurs. This only seems to go wrong in Word 2010, both RTM and SP-1.</p>
<p>The <code>Style </code>object in Word has an old, deprecated, property named <code>.Hidden</code>. You can only see it in the Object Browser in the Word VBE if you choose to &#39;Show Hidden Members&#39;.</p>
<p>Reading the <code>.Hidden </code>property causes no problems.</p>
<p>Setting the <code>.Hidden</code> property to True or False has no effect on the visibility of the style in question.</p>
<p>But setting the <code>.Hidden</code> property of <em>any</em> style to True causes Word to create a new, fake, half-broken duplicate Normal style in your document.</p>
<p>This code, for example. will create a half-baked duplicate Normal style:</p>
<pre>&#39;Do not use this! This creates a broken duplicate Normal style in your document.

ActiveDocument.Styles(wdStyleBodyText).Hidden = True</pre>
<h2>When is this likely to be a problem?</h2>
<p>A half-baked duplicate Normal style is likely to be a problem if you want to cycle though all styles in your document.</p>
<p>You can read some properties of the problem-child Normal style:</p>
<ul>
<li><code>.NameLocal</code></li>
<li><code>.Description</code></li>
<li><code>.Font</code></li>
<li><code>.Frame</code></li>
<li><code>.Shading </code></li>
<li><code>.Table</code></li>
</ul>
<p>If you attempt to read any other property of this problem Normal style, Word throws error 5848 &quot;The style definition is empty&quot;.</p>
<h2>How to avoid the problem</h2>
<p>Don&#39;t apply the <code>.Hidden</code> property to any style, ever.</p>
<h2>How to get around the problem</h2>
<p>If you&#39;re cycling through all the styles in a document, it may be wise to include some error trapping in case you run into a document with this problem.</p>
<p>If you need to access the real Normal style, and don&#39;t want to risk referring to the problem child, do so using Word&#39;s built-in enumerated constant (which is good practice anyway).</p>
<p>So, use this:</p>
<pre>&#39;This is safe
ActiveDocument.Styles(wdStyleNormal)</pre>
<p>not this:</p>
<pre>&#39;This might not be safe
ActiveDocument.Styles(&quot;Normal&quot;)</pre>
<h2>How to get rid of the offending &quot;Normal&quot; style</h2>
<p>I can&#39;t find a way to get rid of the half-baked problem child in the user interface. I can only find it listed in the Manage Styles dialog (Figure 1). If I try to delete the style from there, Word does nothing. Apparently Word can&#39;t distinguish between the real &quot;Normal&quot; and the fake &quot;Normal&quot;.</p>
<p><img alt="Two styles named 'Normal' showing in the Manage Styles dialog"  src="wordimages/Styles/TwoNormalStyles/TwoNormalStyles.png"  style="width: 603px; height: 507px;" /></p>
<p>It seems that the only way to get rid of this style is in code. Word is so protective of the real &quot;Normal&quot; style that we have to re-name the fake to delete it. Something like this seems to work:</p>
<pre>Sub DeleteDuplicateNormalStyle()

Dim sty As Word.Style
Dim nCounter As Long
Dim eStyleType As Word.WdStyleType

    For Each sty In ActiveDocument.Styles
        If sty.NameLocal = &quot;Normal&quot; Then

            On Error Resume Next
            eStyleType = sty.Type

            If Err.Number = 5848 Then
                sty.NameLocal = &quot;DuplicateNormal&quot;
                sty.Delete
                Exit For
            End If
        End If

    Next sty

End Sub</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunakelly.com/word/styles/error-5848-style-definition-is-empty.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reading Conditions of a Word table style (for developers)</title>
		<link>http://www.shaunakelly.com/word/styles/reading-conditions-of-a-word-table-style.html</link>
		<comments>http://www.shaunakelly.com/word/styles/reading-conditions-of-a-word-table-style.html#comments</comments>
		<pubDate>Mon, 15 Aug 2011 01:22:33 +0000</pubDate>
		<dc:creator>Shauna Kelly</dc:creator>
				<category><![CDATA[Styles]]></category>
		<category><![CDATA[Table styles]]></category>

		<guid isPermaLink="false">http://localhost/STK.com/?p=5013</guid>
		<description><![CDATA[The problem A Table style in Word has a .Table.Condition method that returns a ConditionalStyle object. The ConditionalStyle objects refer to different elements of the table: top row, left column, bottom right-hand cell, and so on. There are 12 ConditionalStyle objects in each table style. If you try to access one of these ConditionalStyle objects, [...]]]></description>
			<content:encoded><![CDATA[<h2>The problem</h2>
<p>A Table style in Word has a <code>.Table.Condition</code> method that returns a ConditionalStyle object. The ConditionalStyle objects refer to different elements of the table: top row, left column, bottom right-hand cell, and so on. There are 12 ConditionalStyle objects in each table style.</p>
<p class="Bug1Star" >If you try to access one of these ConditionalStyle objects, some of the time Word will throw error 5825 &#39;Object has been deleted&quot;, even though, plainly, every table style has exactly 12 ConditionalStyle objects, and you can&#39;t delete one even if you tried.</p>
<h2>What causes this error</h2>
<p>You might, for example, assign a table style to a Style variable, and then attempt to access the First Row condition, like this:</p>
<pre>Dim sty As Word.Style
Dim cond As Word.ConditionalStyle

    Set sty = ActiveDocument.Styles(wdStyleTableColorfulGrid)
    Set cond = sty.Table.Condition(wdFirstRow)</pre>
<p>If you run this code on a new document, Word will throw error 5825 &#39;Object has been deleted&#39;.</p>
<p>The problem seems to be that a table style isn&#39;t really ready for use until it&#39;s used in some particular ways. Once you have &quot;primed&quot; the style, it will then work fine. That&#39;s why the error is so difficult to track down: your code errors out the first time, but runs just fine every other time. Or, the same code will work in some circumstances but not others.</p>
<h2>Workaround</h2>
<p>The best way I&#39;ve found to work around this is to read the <code>.Description</code> property before using the <code>.Condition</code> method of a table style&#39;s <code>.Table</code>. This somehow &#39;primes&#39; the Style object and thereafter it will allow you to access the <code>.Condition</code> method.</p>
<p>You don&#39;t have to output the <code>.Description</code> in any way. Just reading it and assigning to a variable will do. So this code will run without error:</p>
<pre>Dim sty As Word.Style
Dim cond As Word.ConditionalStyle
Dim sPrimeTheStyleObject As String

    Set sty = ActiveDocument.Styles(wdStyleTableColorfulGrid)
    sPrimeTheStyleObject = sty.Description
    Set cond = sty.Table.Condition(wdFirstRow)</pre>
<p>The advantage of using the <code>.Description</code> property is that it appears to be innocuous and applies to every style type, so it&#39;s easy to get into the habit of reading the <code>.Description</code> before using the <code>.Condition</code> method.</p>
<p class="RelatedPages" >Related pages</p>
<p><a href="word/word-development/word-reports-the-basestyle-of-styles-inaccurately.html" >Word reports the .BaseStyle of styles inaccurately</a>&nbsp; (the <code>.BaseStyle</code> property of a style doesn&#39;t work until it is &quot;primed&quot;, either)</p>
<p class="RelatedPages" >&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunakelly.com/word/styles/reading-conditions-of-a-word-table-style.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shading (ie background colour) in table styles</title>
		<link>http://www.shaunakelly.com/word/styles/shading-in-table-styles.html</link>
		<comments>http://www.shaunakelly.com/word/styles/shading-in-table-styles.html#comments</comments>
		<pubDate>Sun, 14 Aug 2011 09:29:55 +0000</pubDate>
		<dc:creator>Shauna Kelly</dc:creator>
				<category><![CDATA[Styles]]></category>
		<category><![CDATA[Backgrounds]]></category>
		<category><![CDATA[Colour]]></category>
		<category><![CDATA[Table styles]]></category>

		<guid isPermaLink="false">http://localhost/word/?p=14</guid>
		<description><![CDATA[For developers: how to set the background colour in a table style using the Microsoft Word object model. There are 7 ways to set shading (ie background or foreground colour) on elements of a table style in Microsoft Word. Most don't work. This article describes what does seem to work, and identifies the bugs and annoyances in setting shading in table styles.]]></description>
			<content:encoded><![CDATA[<div class="PopOut QuickReference"   style="display: none;display: none;">
<p>Shading in table styles: what works?</p>
<p>To apply background shading in table styles, apply the shading to a table style&#39;s <code>.Table.Condition</code>.</p>
<p>No other shading works reliably.</p>
</div>
<p>This page is for developers. It&#39;s about table styles (not about an individual table in a document).</p>
<p class="h1_notop" >For table shading information for users see <a class="External"  href="http://www.thedoctools.com/index.php?show=wt_cell_shading"  title="Lene Fredborg's article on table shading" >Table cell shading</a>.</p>
<p>&nbsp;</p>
<p>There are&nbsp;7 ways to set shading (ie background colour) on all or part of a table style using the Word object model. Microsoft has not documented how this is supposed to work. My experience is that, of the 7, two work,&nbsp;more or less,&nbsp;and&nbsp;five don&#39;t. This page describes my experience with setting shading in a table style.</p>
<h2>Shading the style: Doesn&#39;t work</h2>
<p>The object model provides, for example, <code>ActiveDocument.Styles(&quot;MyTableStyle&quot;).Shading</code>.</p>
<p class="Bug5Stars" >As far as I can see, this <code>.Shading</code> object does not work for Table styles.</p>
<p>For character styles and <a href="word/styles/shading-in-paragraph-styles.html"  title="Background and foreground: Shading in paragraph styles" >paragraph</a> styles, you can set the shading directly on the style object. If you try this with a table style, Word throws error 5891 &#39;That property is not available on that object&#39;.</p>
<h2>Shading the style&#39;s .Table: Works a little bit</h2>
<p>To apply shading to the <code>.Table</code> of a table style, this works for any colour:</p>
<pre>ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.Shading.BackgroundPatternColor = wdColorAqua</pre>
<p class="Bug5Stars" >But, there are bugs:</p>
<ul>
<li>Shading the whole table does not work for the built-in style Table Normal. If you attempt to modify Table Normal, Word throws error 4198 &#39;Command failed&#39;.</li>
<li>The three crucial properties of the .Shading object (<code>.BackgroundPatternColor</code>, <code>.Texture</code> and <code>.ForegroundPatternColor</code>) are effectively write-only. No matter what you set:
<ul>
<li><code>.ForegroundPatternColor</code> returns <code>wdColorAutomatic</code></li>
<li><code>.BackgroundPatternColor</code> returns <code>wdColorAutomatic</code></li>
<li><code>.Texture</code> returns <code>wdTextureNone</code>.</li>
</ul>
</li>
<li>You can&#39;t set a <code>.ForegroundPatternColor</code> or a <code>.Texture</code>. You are limited to a single, solid colour. If you set the <code>.ForegroundPatternColor</code> as well as the <code>.BackGroundPatternColor</code>, then Word will ignore the <code>.Texture</code> property and display the table style with the <code>.ForegroundPatternColor</code> as shading.</li>
</ul>
<h2>Shading parts of the table: This works</h2>
<p>You can successfully apply shading to part of the table of a table style. For example, in VBA, the following works for any <code>.Condition</code>, for any colour and any texture:</p>
<pre>With ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.Condition(wdFirstRow).Shading
   .BackgroundPatternColor = wdColorBlue
   .ForegroundPatternColor = wdColorRed
   .Texture = wdTexture15Percent
End With</pre>
<p>Word accurately returns the&nbsp;values for&nbsp;the colours and texture.&nbsp;</p>
<p>In terms of shading, this is the only part of the table style object model that simply works.</p>
<h2>Does not work: Style.ParagraphFormat.Shading.BackgroundPatternColor or Style.Font.Shading.BackgroundPatternColor</h2>
<p>The following don&#39;t work, for any style or for any colour:</p>
<pre>ActiveDocument.Styles(&quot;MyTableStyle&quot;).ParagraphFormat.Shading.BackgroundPatternColor = wdColorRed

ActiveDocument.Styles(&quot;MyTableStyle&quot;).Font.Shading.BackgroundPatternColor = wdColorRed</pre>
<h3>What Word <em>does </em>if you set the .BackgroundPatternColor</h3>
<p class="Bug3Stars" >In Word 2003, in both cases, Word applies white shading. You won&#39;t see that unless the cell already has a visible coloured shading against which to see the white. Further, if you happen to have white text, you now won&#39;t be able to see the text since it&#39;s sitting on top of white shading.</p>
<p>In Word 2007, in both cases, Word ignores the command. The UI shows that the condition&#39;s fill is &#39;No color&#39;.</p>
<h3>What Word <em>tells you it does</em> if you set the .BackgroundPatternColor</h3>
<p class="Bug3Stars" >In both cases, in Word 2003 and Word 2007, Word returns the wrong value. That is, if you set the colour to, eg, <code>wdColorRed</code>, Word will tell you that the shading is red, but you can&#39;t see any red shading: what you see is white shading (in Word 2003) or no shading (in Word 2007). There is no workaround for this, so we cannot read this property.</p>
<h2>Does not work: Style.Table.Condition(n).ParagraphFormat.Shading.BackgroundPatternColor</h2>
<p>The following doesn&#39;t work, for any style, for any .Condition or for any colour:</p>
<pre>ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.Condition(wdFirstRow).ParagraphFormat.Shading.BackgroundPatternColor = wdColorRed</pre>
<h3>What Word <em>does </em>if you set the .BackgroundPatternColor</h3>
<p>In Word 2003, Word applies white shading. You won&#39;t see that unless the cell already has a visible coloured shading against which to see the white. Further, if you happen to have white text, you now won&#39;t be able to see the text since it&#39;s sitting on top of white shading.</p>
<p>In Word 2007, Word ignores the command. The UI shows that the condition&#39;s fill is &#39;No color&#39;.</p>
<h3>What Word <em>tells you it does</em> if you set the .BackgroundPatternColor</h3>
<p class="Bug3Stars" >In both cases, in Word 2003 and Word 2007, Word returns the wrong value, and there is no workaround for this. So we can&#39;t read this property.</p>
<p>If you set the colour to, eg, <code>wdColorRed</code>, you won&#39;t be able to see any red shading: what you see is white shading (in Word 2003) or no shading (in Word 2007). If you ask Word what color is applied, the answer is <code>wdColorRed </code>(ie 255). If you ask Word if the color applied is red, then the answer is True. It&#39;s wrong, but at least it&#39;s consistent. The following VBA code demonstrates:</p>
<pre>Sub TestTableConditionParagraphFormatShading()

Dim sty As Word.Style

Set sty = ActiveDocument.Styles.Add(Name:=&quot;Shauna&quot;, Type:=wdStyleTypeTable)

With sty.Table.Condition(wdFirstRow).ParagraphFormat.Shading
    &#39;Set the first row&#39;s ParagraphFormat shading colour to red
    .BackgroundPatternColor = wdColorRed

    &#39;Ask Word what colour is the shading colour
    Debug.Print .BackgroundPatternColor
    &#39;255

    &#39;Ask Word whether the colour is red
    Debug.Print .BackgroundPatternColor = wdColorRed
    &#39;True
End With

End Sub</pre>
<h2>Does not work: Style.Table.Condition(n).Font.Shading.BackgroundPatternColor</h2>
<p>The following is barely usable:</p>
<pre>ActiveDocument.Styles(&quot;MyTableStyle&quot;).Table.Condition(wdFirstRow).Font.Shading.BackgroundPatternColor = wdColorRed
</pre>
<h3>What Word <em>does </em>if you set the .BackgroundPatternColor</h3>
<p class="Bug3Stars" >In Word 2003, Word does not apply the shading you specify. It applies white shading. You won&#39;t see that unless the cell already has a visible coloured shading against which to see the white. Further, if you happen to have white text, you now won&#39;t be able to see the text since it&#39;s sitting on top of white shading.</p>
<p>In Word 2007 as it was first shipped, Word ignores the command. The UI showed that the condition&#39;s fill is &#39;No color&#39;. With Service Pack 2, Word 2007 applies the shading correctly. Word 2010 applies the shading correctly.</p>
<h3>What Word <em>tells you it does</em> if you set the .BackgroundPatternColor</h3>
<p class="Bug3Stars" >Word 2003, Word 2007 and Word 2010 all return the wrong value. So we cannot read this property in code.</p>
<p>In Word 2003, if you set the colour to, eg, wdColorRed, you won&#39;t be able to see any red shading. What you see is white shading. So I would expect that Word would tell me there was white shading. But no. Word will tell you that the shading is wdUndefined.</p>
<p>In Word 2007 with no service packs, if you set the colour to, eg, wdColorRed, you won&#39;t see any shading. Word will tell you that the shading is wdUndefined.</p>
<p>In Word 2007 with Service Pack 2 and in Word 2010, if you set the colour to, eg, wdColorRed, you will see red shading. But if I set the colour to red, and then ask Word 2007 or Word 2010 if the color applied is red, then the answer is False. Here&#39;s an example in VBA:</p>
<pre>Sub TestTableConditionFontShading()

Dim sty As Word.Style

Set sty = ActiveDocument.Styles.Add(Name:=&quot;Shauna&quot;, Type:=wdStyleTypeTable)

With sty.Table.Condition(wdFirstRow).Font.Shading
    &#39;Set the first row&#39;s Font shading colour to red
    .BackgroundPatternColor = wdColorRed

    &#39;Ask Word what colour is the shading colour
    Debug.Print .BackgroundPatternColor &#39; Returns 9999999

    &#39;Ask Word whether the colour is red
    Debug.Print .BackgroundPatternColor = wdColorRed  &#39; Returns False
End With

End Sub</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunakelly.com/word/styles/shading-in-table-styles.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to hide table styles on the Table Tools Design tab in Word (for developers)</title>
		<link>http://www.shaunakelly.com/word/styles/how-to-hide-table-styles-in-word.html</link>
		<comments>http://www.shaunakelly.com/word/styles/how-to-hide-table-styles-in-word.html#comments</comments>
		<pubDate>Fri, 12 Aug 2011 11:35:36 +0000</pubDate>
		<dc:creator>Shauna Kelly</dc:creator>
				<category><![CDATA[Styles]]></category>
		<category><![CDATA[Table styles]]></category>
		<category><![CDATA[Tables]]></category>
		<category><![CDATA[Templates]]></category>

		<guid isPermaLink="false">http://localhost/STK.com/?p=4995</guid>
		<description><![CDATA[The problem: does anyone need 99 ways to format a table? In Word 2007 and Word 2010, when you click within a table, two Table Tools contextual tabs become available on the Ribbon. The Design tab includes the Table Styles group. This gives you, out of the box, 99 table styles from which to choose. [...]]]></description>
			<content:encoded><![CDATA[<h2>The problem: does anyone need 99 ways to format a table?</h2>
<p>In Word 2007 and Word 2010, when you click within a table, two Table Tools contextual tabs become available on the Ribbon.</p>
<p>The Design tab includes the Table Styles group. This gives you, out of the box, 99 table styles from which to choose.</p>
<p>Having applied one of the 99 styles, the user can then choose whether or not to show banded columns, banded rows, header or total rows and so on.</p>
<p>In a corporate environment, the communications people would tear their hair out if users formatted tables in 99 different ways. A corporate environment is likely to have 2 or 3 &#39;approved&#39; ways to format a table.</p>
<h2>The solution: hide most, if not all, of the built-in table styles</h2>
<p>Well-constructed templates for corporate use are likely to have 2 or 3 custom table styles that fit the corporate branding. Or, the in-house rules may be that 2 or 3 of the built-in styles are to be used, but the rest are off limits.</p>
<p class="Bug1Star" >There is no way in the user interface to hide the built-in table styles.</p>
<p>But you can do it in code. Something like this will do the trick:</p>
<pre>Sub HideATableStyle()

    With ActiveDocument.Styles(Word.wdStyleTableLightShading)
        .Visibility = True &#39; Yes, True.
        .UnhideWhenUsed = False
    End With

End Sub</pre>
<p>If you&#39;re creating a template for corporate use, it may be appropriate to hide most of the built-in table styles in the template. Leave the approved custom or built-in table styles visible. Users can then easily apply the corporate-approved table styles when working on documents based on that template.</p>
<p>But&#8230; there is a disadvantage to this method. If the user copies a table from another document, and that table has your hidden style applied to it, then the user cannot see what style has been applied to the table. To avoid that, use something like this:</p>
<pre>Sub HideATableStyleButMakeItVisibleWhenUsed()

    With ActiveDocument.Styles(Word.wdStyleTableLightShading)
        .Visibility = True &#39; Yes, True.
        .UnhideWhenUsed = True
    End With

End Sub</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunakelly.com/word/styles/how-to-hide-table-styles-in-word.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to detect frames in paragraph styles</title>
		<link>http://www.shaunakelly.com/word/styles/frames-in-paragraph-styles.html</link>
		<comments>http://www.shaunakelly.com/word/styles/frames-in-paragraph-styles.html#comments</comments>
		<pubDate>Tue, 09 Aug 2011 09:23:31 +0000</pubDate>
		<dc:creator>Shauna Kelly</dc:creator>
				<category><![CDATA[Styles]]></category>
		<category><![CDATA[Frames]]></category>
		<category><![CDATA[Paragraph styles]]></category>

		<guid isPermaLink="false">http://localhost/STK.com/word/?p=2407</guid>
		<description><![CDATA[In the user interface, it is obvious if a paragraph style has a frame. It's not so obvious in the Word object model. There is no built-in method to determine whether a style has a Frame. This article identifies one possible way around this problem.]]></description>
			<content:encoded><![CDATA[<p>In the user interface, it is obvious if a paragraph style has a frame.</p>
<ol>
<li>The frame is <strong>visible</strong>: when you click in a paragraph of that style, you can see the frame boundaries.</li>
<li>The frame is <strong>functional</strong>: content will wrap around the paragraph according to the settings of the frame.</li>
</ol>
<div class="ImageInLine"  style="width: 519px;" >
<p><img alt="Style formatted with a Frame in Word 2010"  src="wordimages/frames/Frame2010.png"  style="width: 519px; height: 120px;" /></p>
<p>Figure 1: In Word 2007 and Word 2010, a frame displays as a dashed blue line when content inside the frame is selected</p>
</div>
<p>It&#39;s not so obvious in the Word object model.</p>
<p>The object model gives us a .Delete method to remove a frame. For example:</p>
<pre>ActiveDocument.Styles(&quot;MyStyle&quot;).Frame.Delete</pre>
<p>But there is no way to add a frame to a style. The <code>.Frame</code> property returns a Frame object whether or not the style has a frame that is visible in the user interface. From the point of view of the object model, a frame is present for all paragraph styles.</p>
<p class="Bug3Stars" >There is no obvious way to detect the presence of a Frame as the user experiences it. That is, if I want to know whether the frame for a style is visible and functional, there is nothing in the object model that tells me.</p>
<p>However, testing suggests that testing the <code>.Width</code> and <code>.Height</code> properties of a style&#39;s Frame give us a proxy for identifying the presence of a frame.</p>
<p>If the .Width and .Height of the frame equal -1, then the frame is not visible and not functional. You cannot set the <code>.Width</code> or <code>.Height</code> to -1 (you get a message saying that the measure must be between 0.5pt and 1584pt). It seems that the only way that <code>.Width</code> and <code>.Height</code> come to be -1 is if there is no visible, functional frame.</p>
<p>Microsoft has not documented the use of <code>.Width</code> and <code>.Height</code> as a proxy to detect whether a paragraph style has a frame. I discovered it by testing, and it has been reliable for me. YMMV, as they say.</p>
<p>Follow up:&nbsp; One person says that this method does not work for him, but Cindy Meister provides an alternative solution: <a class="External"  href="http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/6a06f149-94a2-4fa0-8026-738b1c315261/" >http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/6a06f149-94a2-4fa0-8026-738b1c315261/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunakelly.com/word/styles/frames-in-paragraph-styles.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

