tag:blogger.com,1999:blog-27603347170118088192024-02-20T18:30:04.104-08:00Macros in MinutesTake two minutes to paste a macro into your Normal template, and improve your life!Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-2760334717011808819.post-19710493314178942802021-05-26T17:52:00.000-07:002011-06-07T17:01:01.223-07:00Getting You StartedFind a macro you like. Load MSWord. Alt-F11 to enter the Visual Basic Editor. Choose Insert Module to insert a module in your Normal.dot. Paste in my code. Have fun and be more profitable.<br />Queries? Meet me at www.ChrisGreaves.comUnder The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-55939678895530811392011-11-29T07:54:00.000-08:002011-11-29T07:56:18.092-08:00Convert Hyperlinks To Proper CaseI create small files "TableOfContents" for use in my web pages. <p class="Picture"><img src="http://www.chrisgreaves.com/MacrosInMinutes/ProperCase_001.png" alt="Visit www.ChrisGreaves.com for this image! ProperCase_001.png" /></p> <p class="Body_Text">By mis-adventure I often enough end up with hyperlinks in a mish-mash of cases.</p> <p class="Body_Text">I'd like all the hyperlinks to conform to a consistent standard.</p> <pre style="color: rgb(204, 0, 0);">Sub ConvertHyperlinksToProperCase()<p> Dim HLNK As Hyperlink</p><p> For Each HLNK In ActiveDocument.Hyperlinks</p><p> With HLNK</p><p> Dim strTextToDisplay As String</p><p> strTextToDisplay = .TextToDisplay</p><p> .TextToDisplay = StrConv(strTextToDisplay, vbProperCase)</p><p> End With</p><p> Next HLNK</p><p>End Sub</p></pre> <p class="Body_Text">This little macro does that.</p> <p class="Picture"><img src="http://www.chrisgreaves.com/MacrosInMinutes/ProperCase_002.png" alt="Visit www.ChrisGreaves.com for this image! ProperCase_002.png" /></p> <p class="Body_Text">Note that it processes EVERY hyperlink in the current document, which is fine for me.</p> <p class="Body_Text">If you wanted it to operate only on a selected area you could change one line to read</p> <pre style="color: rgb(204, 0, 0);"><p> For Each HLNK In Selection.Hyperlinks</p></pre>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-23410820929194307022011-10-03T07:40:00.000-07:002011-10-31T10:57:16.399-07:00Quick Keys QuickiesWe’ve all faced the problem of making a simple change to a series of paragraphs in a document, or inserting some choice item in each cell of a table, cases where Microsoft Word’s Edit-replace just can’t get the job done. <p class="Body_Text">The mantra is “<span style="color: rgb(102, 51, 255);">If it’s boring and repetitive, WRITE A MACRO</span>”, but who has time to catalogue a vast array of macros which, having been used once, can be discarded?</p> <p class="Body_Text">The solution lies in recording a macro and assigning it to a fixed shortcut key combination, and to ease your transition into this amazing world, I’ve recorded a three-minute video which you can see through <a href="http://www.youtube.com/watch?v=mTr397V5DHM">YouTube</a>, or in <a href="http://www.chrisgreaves.com/Videos/OnTheFlyMacros.wmv">higher definition</a> (and longer download time) from <a href="http://www.chrisgreaves.com/Videos/index.htm">my video collection</a>.</p> <p class="Body_Text">I’ll spell out the keyboard sequences you need in the table below; you may want to print it out for future reference.</p> <p class="Body_Text">In the table below I suggest you use Ctrl-Shift-K as your shortcut key combination; it is not assigned to any special command in Microsoft Word, and is easy to remember.</p> <p class="Body_Text">I’ve used “{Your keyboard sequence}” to represent whatever keystrokes you require to perform your action one time. You will, of course, merely use the keyboard to perform your action one time.</p><table class="3DMsoTableGrid" style="" 4pt="" 0cm="" window="text;" 75pt="" outset="" windowtext="" border="1" cellpadding="3D0" cellspacing="3D3"><tbody><tr style=""><br /><td style="" 0cm="" 4pt="" valign="3Dtop"><br /><p class="3DBodyTextTable">Keyboard sequence<o:p></o:p></p><br /></td><br /><td style="" 0cm="" 4pt="" valign="3Dtop"><br /><p class="3DBodyTextTable">Full command<o:p></o:p></p><br /></td><br /></tr><br /><tr style=""><br /><td style="" 0cm="" 4pt="" valign="3Dtop"><br /><p class="3DBodyTextTable">Alt-T, M, R<o:p></o:p></p><br /></td><br /><td style="" 0cm="" 4pt="" valign="3Dtop"><br /><p class="3DBodyTextTable">Choose Tools, Macro, Record<o:p></o:p></p><br /></td><br /></tr><br /><tr style=""><br /><td style="" 0cm="" 4pt="" valign="3Dtop"><br /><p class="3DBodyTextTable">Alt-K, Ctrl-Shift-K, Enter, Enter<o:p></o:p></p><br /></td><br /><td style="" 0cm="" 4pt="" valign="3Dtop"><br /><p class="3DBodyTextTable">Choose Keyboard, Ctrl-Shift-K as the shortcut key<br />combination, Assign, Close.<o:p></o:p></p><br /></td><br /></tr><br /><tr style=""><br /><td style="" 0cm="" 4pt="" valign="3Dtop"><br /><p class="3DBodyTextTable">{Your keyboard sequence}<o:p></o:p></p><br /></td><br /><td style="" 0cm="" 4pt="" valign="3Dtop"><br /><p class="3DBodyTextTable">Here is where you will use the keyboard to perform the<br />action, one <span class="3DGramE">time, that</span> you want to assign to<br />Ctrl-Shift-K.<o:p></o:p></p><br /></td><br /></tr><br /><tr style=""><br /><td style="" 0cm="" 4pt="" valign="3Dtop"><br /><p class="3DBodyTextTable">Alt-T, M, R<o:p></o:p></p><br /></td><br /><td style="" 0cm="" 4pt="" valign="3Dtop"><br /><p class="3DBodyTextTable">Choose Tools, Macro, stop Recording.<o:p></o:p><= /p><br /></p></td><br /></tr><br /></tbody></table><br /><p class="Body_Text">That’s it!</p> <p class="Body_Text">Position your cursor at the start of the text to be modified, hold down both the Ctrl and Shift keys, and tap the letter “K” repeatedly.</p> <p class="Body_Text">Here’s a full example of my assigning to Ctrl-Shift-K a macro that will insert alternate sequence fields at the head of a set of paragraphs.</p> <table class="TableFormatWeb1"> <tbody><tr> <th><p class="Body_Text_Table">Keyboard sequence</p></th> <th><p class="Body_Text_Table">Full command</p></th> </tr> <tr> <td><p class="Body_Text_Table">Alt-T, M, R</p></td> <td><p class="Body_Text_Table">Choose Tools, Macro, Record</p></td> </tr> <tr> <td><p class="Body_Text_Table">Alt-K, Ctrl-Shift-K, Enter, Enter</p></td> <td><p class="Body_Text_Table">Choose Keyboard, Ctrl-Shift-K as the shortcut key combination, Assign, Close.</p></td> </tr> <tr> <td><br /></td> <td><br /></td> </tr> <tr> <td><p class="Body_Text_Table">(, Ctrl-F9,seq,,question,, ,),</p></td> <td><p class="Body_Text_Table">This inserts a sequence field “question”, surrounded by parentheses, with a space between the closing parenthesis and the paragraph text.</p></td> </tr> <tr> <td><p class="Body_Text_Table">Ctrl-Down-Arrow</p></td> <td><p class="Body_Text_Table">This moves to the next paragraph</p></td> </tr> <tr> <td><p class="Body_Text_Table">(, Ctrl-F9,seq,,answer,, ,),</p></td> <td><p class="Body_Text_Table">This inserts a sequence field “answer”, surrounded by parentheses, with a space between the closing parenthesis and the paragraph text.</p></td> </tr> <tr> <td><p class="Body_Text_Table">Ctrl-Down-Arrow</p></td> <td><p class="Body_Text_Table">This moves to the next paragraph</p></td> </tr> <tr> <td><br /></td> <td><br /></td> </tr> <tr> <td><p class="Body_Text_Table">Alt-T, M, R</p></td> <td><p class="Body_Text_Table">Choose Tools, Macro, stop Recording.</p></td> </tr> </tbody></table> <pre></pre>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-24151078767553475972011-09-30T09:04:00.000-07:002011-09-30T09:07:52.033-07:00Detect Duplicate words in sentencesThis little macro detects duplicated words in sentences.<br />unlike Microsoft Word's grammar/spell checker which merely identifies consecutive duplicate words, this macro (and associated function) marks in <span style="color: rgb(255, 0, 0);">RED</span> second and subsequent occurrences of words in each sentence.<br />A short list of noise words is provided as a string constant; we don't mind those words being repeated.<br /><pre style="color: rgb(204, 0, 0);">Public Const strcIgnoreWords As String = vbTab & "and" & vbTab & "on" & vbTab & "the" & vbTab<br />Sub DuplicateWordsInSentences()<br /> Dim prg As Paragraph<br /> For Each prg In ActiveDocument.Paragraphs<br /> Dim snt As Range<br /> For Each snt In prg.Range.Sentences<br /> Call FindDupInSentence(snt)<br /> Next snt<br /> Next prg<br />End Sub<br />Function FindDupInSentence(snt As Range)<br /> Dim strAllWords As String<br /> strAllWords = vbTab<br /> Dim wd As Range<br /> For Each wd In snt.Words<br /> Dim strWd As String<br /> strWd = Trim(wd.Text)<br /> If Len(strWd) > 1 Then<br /> If InStr(1, strcIgnoreWords, vbTab & strWd & vbTab) > 0 Then ' we ignore this word<br /> Else<br /> If InStr(1, strAllWords, vbTab & strWd & vbTab) > 0 Then<br /> wd.Font.Color = wdColorRed<br /> Else<br /> strAllWords = strAllWords & strWd & vbTab<br /> End If<br /> End If<br /> Else ' we ignore words of length 1 character<br /> End If<br /> Next wd<br />End Function<br /></pre>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-67184130582930029142011-09-19T07:23:00.001-07:002011-09-19T07:26:34.737-07:00File DiversionYour new system came in today, and while you are all free to read Word documents from the old server, you are all supposed to save files to the new server on drive J:.<br />Here's some stripped-down proof-of-concept code:<pre style="color: rgb(204, 0, 0);">Public Const strcNewDrive As String = "J:"<br />Sub FileSave()<br /> MsgBox "FileSave"<br /> If Len(ActiveDocument.Path) = 0 Then ' not previously saved<br /> Call SaveAsDialog(strcNewDrive, ActiveDocument.Name)<br /> Else<br /> If UCase(Left(ActiveDocument.Path, 2)) = strcNewDrive Then ' User is logged on to th drive<br /> ActiveDocument.Save<br /> Else<br /> Call SaveAsDialog(strcNewDrive, ActiveDocument.Name)<br /> End If<br /> End If<br />End Sub<br />Sub FileSaveAs()<br /> MsgBox "FileSaveAs"<br /> Call SaveAsDialog(strcNewDrive, ActiveDocument.Name)<br />End Sub<br />Function SaveAsDialog(strDrive As String, strName As String)<br /> With Application.Dialogs(wdDialogFileSaveAs)<br /> .Name = strDrive & "\" & strName<br /> .Format = wdFormatDocument<br /> .Show<br /> End With<br />End Function<br /></pre>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-61132454096727288202011-08-31T09:32:00.000-07:002011-08-31T09:34:45.275-07:00Rebuild your Active DocumentYour document is corrupt, or it is so heavily edited that it is behaving badly.
<br />Use the little macro "<span style="font-size: 12pt; font-family: "Times New Roman"; font-weight: bold; color: rgb(204, 0, 0);">RebuildActiveDocument</span>" to grab all your text, unformatted, and rebuild the document.
<br />CAUTION: make a copy of your document using Windows Explorer before running this macro.
<br />
<br /><!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:View> <w:zoom>0</w:Zoom> <w:punctuationkerning/> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:SaveIfXMLInvalid> <w:ignoremixedcontent>false</w:IgnoreMixedContent> <w:alwaysshowplaceholdertext>false</w:AlwaysShowPlaceholderText> <w:compatibility> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> </w:Compatibility> <w:browserlevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><span style="font-size: 12pt; font-family: "Times New Roman";"><pre style="color: rgb(204, 0, 0);">Sub RebuildActiveDocument()
<br /><span style=""> </span>' Get the name of the source ActiveDocumentument
<br /><span style=""> </span>Dim strFilename As String
<br /><span style=""> </span>strFilename = ActiveDocument.FullName
<br /><span style=""> </span>' Get the stoty-content of the ActiveDocumentument
<br /><span style=""> </span>Dim strStoryContent As String
<br /><span style=""> </span>Dim lng As Long
<br /><span style=""> </span>For lng = 1 To ActiveDocument.StoryRanges.Count
<br /><span style=""> </span>strStoryContent = strStoryContent & ActiveDocument.StoryRanges(lng).Text
<br /><span style=""> </span>Next lng
<br /><span style=""> </span>' Close the ActiveDocumentument WITHOUT saving changes
<br /><span style=""> </span>ActiveDocument.Close (wdDoNotSaveChanges)
<br /><span style=""> </span>' Create a new ActiveDocumentument
<br /><span style=""> </span>Documents.Add
<br /><span style=""> </span>' Insert the text file
<br /><span style=""> </span>Selection.TypeText (strStoryContent)
<br /><span style=""> </span>' Save the ActiveDocumentument with the original name
<br /><span style=""> </span>ActiveDocument.SaveAs (strFilename)
<br />End Sub</pre></span>
<br />Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-66826807543250973522011-08-18T07:07:00.000-07:002011-08-18T07:23:42.682-07:00Print View, Whole page, All documentsFrom time to time I find myself reviewing or updating a set of a dozen or so documents.
<br />
<br />I like to see them in a consistent manner.
<br />
<br />Perhaps they are a set of flyers, and I want to make sure that the layout above-the-fold is identical.
<br />
<br />This little macro loops through all open documents, moves the cursor to the top of the document, then chooses Print View (WYSIWYG, almost) and a whole-page on the screen.
<br /><!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:View> <w:zoom>0</w:Zoom> <w:punctuationkerning/> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:SaveIfXMLInvalid> <w:ignoremixedcontent>false</w:IgnoreMixedContent> <w:alwaysshowplaceholdertext>false</w:AlwaysShowPlaceholderText> <w:compatibility> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> </w:Compatibility> <w:donotoptimizeforbrowser/> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--> <p class="MsoMacroText"></p><pre style="color: rgb(204, 0, 0);">Sub PrintViewAll()
<br /><span style=""> </span>Dim doc As Document
<br /><span style=""> </span>For Each doc In Application.Documents
<br /><span style=""> </span>doc.Activate
<br /><span style=""> </span>Selection.HomeKey Unit:=wdStory
<br /><span style=""> </span>ActiveWindow.View.Type = wdPrintView
<br /><span style=""> </span>ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitFullPage
<br /><span style=""> </span>Application.WindowState = wdWindowStateMaximize\
<br /><span style=""> </span>Next doc
<br />End Sub</pre>
<br />
<br />P.S. If you'd rather be left at the foot of the documents, to append new text, use:-
<br /><pre style="color: rgb(204, 0, 0);">Selection.EndKey Unit:=wdStory</pre>P.P.S. If you'd rather be left in Normal view, use:
<br /><pre style="color: rgb(204, 0, 0);">ActiveWindow.View.Type = wdNormalView</pre>
<br />Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-57522403369902099092011-08-09T07:22:00.000-07:002011-08-09T07:25:26.126-07:00File,Close (No Save)I'm feeling guilty about the length of the previous post.
<br />I hope you'll accept this token of remorse.
<br />
<br />We use Ctrl-F4 to close a document, and of course if the contents of the document have changed we get to answer the skill-testing question "Do you want to save?".
<br />Oftentimes we know in advance that we don't want the changes. Perhaps we have been experimenting with the document and want to discard all changes before we accidentally overwrite the good version.
<br />
<br />Closing a File (document) without saving changes is a one-liner, as shown below.
<br />
<br />For extra utility you may want to assign an unused shortcut key combination to this macro.
<br /><!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:View> <w:zoom>0</w:Zoom> <w:punctuationkerning/> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:SaveIfXMLInvalid> <w:ignoremixedcontent>false</w:IgnoreMixedContent> <w:alwaysshowplaceholdertext>false</w:AlwaysShowPlaceholderText> <w:compatibility> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> </w:Compatibility> <w:donotoptimizeforbrowser/> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--> <p class="MsoMacroText"></p><pre style="color: rgb(204, 0, 0);">Sub FileCloseNoSave()
<br /><span style=""> </span>ActiveDocument.Close (wdDoNotSaveChanges)
<br />End Sub</pre>
<br />Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-37890512397793019592011-08-08T13:50:00.000-07:002011-08-08T13:55:28.254-07:00Mark Duplicated Words<!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:View> <w:zoom>0</w:Zoom> <w:punctuationkerning/> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:SaveIfXMLInvalid> <w:ignoremixedcontent>false</w:IgnoreMixedContent> <w:alwaysshowplaceholdertext>false</w:AlwaysShowPlaceholderText> <w:compatibility> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> </w:Compatibility> <w:donotoptimizeforbrowser/> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><span style=";font-family:";font-size:12pt;" >If you'd like an easy way to improve your writing style, try this lengthy-looking macro and function.
<br />It examines each sentence in your document looking for repeated words.
<br />A string "strDismiss" is set up to avoid reporting words which I think are allowed to be repeated.
<br />repeated words are flagged with Microsoft Word's character style "Strong", so you may want to modify that in your Normal.dot to be bright pink, 16 point, or whatever.
<br />Don't forget that you can clear all local formatting with Ctrl-A followed by Ctrl-Space.
<br />
<br /><pre style="color: rgb(204, 0, 0);">Public strDismiss As String
<br />Sub MarkDuplicatedWords()
<br /><span style=""> </span>strDismiss = vbTab & "for" & vbTab & "and" & vbTab & "that" & vbTab & "," & vbTab & "." & vbTab & "to" & vbTab
<br /><span style=""> </span>strDismiss = strDismiss & "http" & vbTab & "://" & vbTab & "www" & vbTab & "com" & vbTab & "/" & vbTab & "the" & vbTab
<br /><span style=""> </span>strDismiss = strDismiss & "a" & vbTab & "of" & vbTab & "www" & vbTab & "com" & vbTab & "/" & vbTab & "the" & vbTab
<br /><span style=""> </span>strDismiss = strDismiss & """" & vbTab & "of" & vbTab & "www" & vbTab & "com" & vbTab & "/" & vbTab & "the" & vbTab
<br /><span style=""> </span>Dim prg As Paragraph
<br /><span style=""> </span>For Each prg In ActiveDocument.Paragraphs
<br /><span style=""> </span>Dim snt As Range
<br /><span style=""> </span>For Each snt In prg.Range.Sentences
<br /><span style=""> </span>If lngCountDuplicatedWords(snt, strDismiss, ActiveDocument.Styles("Strong")) > 0 Then
<br /><span style=""> </span>Else
<br /><span style=""> </span>End If
<br /><span style=""> </span>Next snt
<br /><span style=""> </span>Next prg
<br />End Sub
<br />Function lngCountDuplicatedWords(rng As Range, strDismiss As String, sty As Style)
<br /><span style=""> </span>Dim lngResult As Long
<br /><span style=""> </span>Dim strSentence As String
<br /><span style=""> </span>strSentence = vbTab
<br /><span style=""> </span>Dim wd As Range
<br /><span style=""> </span>For Each wd In rng.Words
<br /><span style=""> </span>Dim strWord As String
<br /><span style=""> </span>strWord = Trim(wd.Text)
<br /><span style=""> </span>If InStr(1, strDismiss, vbTab & strWord & vbTab) > 0 Then ' we can ignore this word
<br /><span style=""> </span>Else
<br /><span style=""> </span>If InStr(1, strSentence, vbTab & strWord & vbTab) > 0 Then
<br /><span style=""> </span>lngResult = lngResult + 1
<br /><span style=""> </span>wd.Style = sty
<br /><span style=""> </span>Else
<br /><span style=""> </span>strSentence = strSentence & strWord & vbTab
<br /><span style=""> </span>End If
<br /><span style=""> </span>End If
<br /><span style=""> </span>Next wd
<br /><span style=""> </span>lngCountDuplicatedWords = lngResult
<br />End Function
<br /></pre></span>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-83096392761698470972011-07-26T12:24:00.000-07:002011-07-26T12:27:43.050-07:00ToggleShowAllI assign this cute trick to the Shift-Ctrl-8 keyboard shortcut.<br />It flip-flops between showing everything that's going on in my document, to showing nothing but pristine text and graphics.<br /><br /><br /><!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:View> <w:zoom>0</w:Zoom> <w:punctuationkerning/> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:SaveIfXMLInvalid> <w:ignoremixedcontent>false</w:IgnoreMixedContent> <w:alwaysshowplaceholdertext>false</w:AlwaysShowPlaceholderText> <w:compatibility> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> </w:Compatibility> <w:donotoptimizeforbrowser/> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--> <p class="MsoMacroText"></p><pre style="color: rgb(204, 0, 0);">Public Sub ToggleShowAll()<br /><span style=""> </span>'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br /><span style=""> </span>''' Function:<span style=""> </span>ToggleShowAll<br /><span style=""> </span>'''<br /><span style=""> </span>''' Comments:<span style=""> </span>Use the current "Show Fields" setting (True or False) to toggle all visibility settings.<br /><span style=""> </span>'''<br /><span style=""> </span>''' Arguments:<span style=""> </span>None.<br /><span style=""> </span>'''<br /><span style=""> </span>''' Returns:<span style=""> </span>None<br /><span style=""> </span>'''<br /><span style=""> </span>''' Date<span style=""> </span>Developer<span style=""> </span>Action<br /><span style=""> </span>''' --------------------------------------------------------------------------<br /><span style=""> </span>''' 2006/03/21<span style=""> </span>Chris Greaves<span style=""> </span>Created<br /><span style=""> </span>'''<br /><span style=""> </span>''' The setting ShowFieldCodes<span style=""> </span>will be used to control the settings of<span style=""> </span>ShowFieldCodes, ShowAll , ShowFieldCodes , ShowHiddenText , ShowTabs , ShowSpaces , ShowParagraphs and ShowBookmarks.<br /><span style=""> </span>''' All flags will be set to the opposite of the current setting of ShowFieldCodes.<br /><span style=""> </span>''' If ShowFieldCodes is ON, all flags will be set OFF.<br /><span style=""> </span>''' If ShowFieldCodes is OFF, all flags will be set ON.<br /><span style=""> </span>''' The new setting will be saved as the key "Show All" in the Application Environment file.<br /><span style=""> </span>If Documents.Count > 0 Then<br /><span style=""> </span>Dim boolSet As Boolean<br /><span style=""> </span>boolSet = Not ActiveWindow.View.ShowFieldCodes<br /><span style=""> </span>With ActiveWindow.View<br /><span style=""> </span>.ShowAll = boolSet<br /><span style=""> </span>.ShowFieldCodes = boolSet<br /><span style=""> </span>.ShowHiddenText = boolSet<br /><span style=""> </span>.ShowTabs = boolSet<br /><span style=""> </span>.ShowSpaces = boolSet<br /><span style=""> </span>.ShowParagraphs = boolSet<br /><span style=""> </span>.ShowBookmarks = boolSet<br /><span style=""> </span>End With<br /><span style=""> </span>Dim strSet As String<br /><span style=""> </span>If boolSet Then<br /><span style=""> </span>strSet = "Y"<br /><span style=""> </span>Else<br /><span style=""> </span>strSet = "N"<br /><span style=""> </span>End If<br /><span style=""> </span>Else<br /><span style=""> </span>End If<br />End Sub</pre> <span style="color: rgb(255, 0, 0);font-family:courier new;" ><br /></span><span style="color: rgb(255, 0, 0);font-family:courier new;" ></span>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-32086523466653155132011-06-25T13:46:00.000-07:002011-06-25T13:48:41.908-07:00Close All But ActiveFrom time to time I find that I have opened a slew of documents, just to help me understand the one document I'm working on.<br />In this case I want to violate my Golden Rule of "Never Close, never Minimize", and close all open documents EXCEPT THE ACTIVE DOCUMENT without saving a single one; discard all recent changes.<br />This little macro does the trick.<br /><!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:View> <w:zoom>0</w:Zoom> <w:punctuationkerning/> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:SaveIfXMLInvalid> <w:ignoremixedcontent>false</w:IgnoreMixedContent> <w:alwaysshowplaceholdertext>false</w:AlwaysShowPlaceholderText> <w:compatibility> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> </w:Compatibility> <w:browserlevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><span style="font-size: 12pt; font-family: "Times New Roman";"><pre style="color: rgb(204, 0, 0);">Public Sub CloseAllButActive()<br /><span style=""> </span>''' Close all open documents EXCEPT THE ACTIVE DOCUMENT without saving a single one; discard all recent changes.<br /><span style=""> </span>If Documents.Count > 0 Then<br /><span style=""> </span>Dim docSave As Document<br /><span style=""> </span>Set docSave = ActiveDocument<br /><span style=""> </span>Dim doc As Document<br /><span style=""> </span>For Each doc In Application.Documents<br /><span style=""> </span>If doc <> docSave Then<br /><span style=""> </span>doc.Close savechanges:=wdDoNotSaveChanges<br /><span style=""> </span>Else<br /><span style=""> </span>End If<br /><span style=""> </span>Next doc<br /><span style=""> </span>Else ' nothing to do<br /><span style=""> </span>End If<br />End Sub</pre></span>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-34991107014541522982011-06-12T13:49:00.000-07:002011-06-12T13:51:55.131-07:00Jump To Document FolderYou've just saved your file, or you are wondering about another file in the same folder, so you need to open Windows Explorer and work your way through the trees to your folder.<br />That would be Alt-Tab to Explorer (or Start, Run,<span style="font-style: italic;"> explorer.exe</span>), click, double-click, click etc.<br /><span style="font-weight: bold;">Right?</span><br /><span style="font-style: italic; font-weight: bold;">Wrong!</span><br />Use the little macro below<br /><br /><!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:View> <w:zoom>0</w:Zoom> <w:punctuationkerning/> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:SaveIfXMLInvalid> <w:ignoremixedcontent>false</w:IgnoreMixedContent> <w:alwaysshowplaceholdertext>false</w:AlwaysShowPlaceholderText> <w:compatibility> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> </w:Compatibility> <w:browserlevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><span style="font-size: 12pt; font-family: "Times New Roman";"><pre style="color: rgb(204, 0, 0);">Public Sub JumpToDocumentFolder()<br /><span style=""> </span>''' Launch Windows Explorer into the current document's folder.<br /><span style=""> </span>Call Shell("explorer.exe /e," & ActiveDocument.Path, vbMaximizedFocus)<br />End Sub</pre></span>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-81310610101624579932011-06-07T16:58:00.000-07:002011-06-07T17:00:07.121-07:00Delete All Paragraphs This StyleFrom time to time I have occasion to remove globs of text from a document leaving bits behind.<br />For example, I might want to delete all 'Normal" styled paragraphs and leave only the 'Heading " styled paragraphs behind.<br />This macro does the trick, regardless of the styles in use!<br /><br /><!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:View> <w:zoom>0</w:Zoom> <w:punctuationkerning/> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:SaveIfXMLInvalid> <w:ignoremixedcontent>false</w:IgnoreMixedContent> <w:alwaysshowplaceholdertext>false</w:AlwaysShowPlaceholderText> <w:compatibility> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> </w:Compatibility> <w:donotoptimizeforbrowser/> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><span style="font-size: 12pt; font-family: "Times New Roman";"><pre style="color: rgb(204, 0, 0);">Sub DeleteAllParagraphsThisStyle()<br /><span style=""> </span>''' Place the text cursor in a paragraph, run the macro.<br /><span style=""> </span>''' All paragraphs in that (selected) style will be removed from the document.<br /><span style=""> </span>Dim strStyleName As String<br /><span style=""> </span>strStyleName = Selection.Paragraphs(1).Range.Style<br /><span style=""> </span>Dim lng As Long<br /><span style=""> </span>For lng = ActiveDocument.Paragraphs.Count To 1 Step -1<br /><span style=""> </span>If ActiveDocument.Paragraphs(lng).Style = strStyleName Then<br /><span style=""> </span>ActiveDocument.Paragraphs(lng).Range.Delete<br /><span style=""> </span>Else<br /><span style=""> </span>End If<br /><span style=""> </span>Next lng<br />End Sub</pre></span>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-1501133387584807422011-06-07T04:07:00.000-07:002011-06-07T04:09:48.254-07:00CloseAllTakeNoPrisonersAlthough as a rule I "Never Close, Never Minimize", I confess to times when I have literally dozens of documents left open after a failed attempt to batch-process a folder.<br />At that time I like to fix the problem and start with a clean slate.<br />The little macro below shrugs and wipes my slate clean!<br /><br /><!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:View> <w:zoom>0</w:Zoom> <w:punctuationkerning/> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:SaveIfXMLInvalid> <w:ignoremixedcontent>false</w:IgnoreMixedContent> <w:alwaysshowplaceholdertext>false</w:AlwaysShowPlaceholderText> <w:compatibility> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> </w:Compatibility> <w:donotoptimizeforbrowser/> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><span style="font-size: 12pt; font-family: "Times New Roman";"><pre style="color: rgb(204, 0, 0);">Public Sub CloseAllTakeNoPrisoners()<br /><span style=""> </span>''' Close all open documents without saving a single one; discard all recent changes.<br /><span style=""> </span>Dim doc As Document<br /><span style=""> </span>For Each doc In Application.Documents<br /><span style=""> </span>doc.Close savechanges:=wdDoNotSaveChanges<br /><span style=""> </span>Next doc<br /><span style=""> </span>If Documents.Count > 0 Then<br /><span style=""> </span>Documents.Close savechanges:=wdDoNotSaveChanges<br /><span style=""> </span>Else<br /><span style=""> </span>End If<br />End Sub</pre></span>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-43425442469864226292011-06-06T04:31:00.000-07:002011-06-06T04:34:02.173-07:00Close without saving changesDo you ever get partway through changing a Word document and think "Oh this is totally silly"?<br />Here's the macro to shut down what you're doing and abandon all changes.<br /><span style="font-weight: bold;">Effortlessly</span>.<br />Without getting confused over Word's skill-testing questions late at night.<br /><pre style="color: rgb(204, 0, 0);">Public Sub CloseNoSave()<br /> ''' Close the current document without saving it<br /> ActiveDocument.Close (wdDoNotSaveChanges)<br />End Sub</pre>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-72155916454426286372011-05-28T09:38:00.000-07:002011-05-28T09:40:38.549-07:00Revert to Saved File<!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:View> <w:zoom>0</w:Zoom> <w:punctuationkerning/> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:SaveIfXMLInvalid> <w:ignoremixedcontent>false</w:IgnoreMixedContent> <w:alwaysshowplaceholdertext>false</w:AlwaysShowPlaceholderText> <w:compatibility> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> </w:Compatibility> <w:donotoptimizeforbrowser/> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><span style="font-size: 12pt; font-family: "Times New Roman";">Choosing Edit, Undo (or better yet, using Ctrl-Z) is all very well for a few changes, but a professional saves their work every time a significant change has been made, or every time they embark on a risky manoeuvre.<br />Some of us save our work before we pick up the phone, or as we hear a colleague approaching.<br />That means that our saved file is the best source of recovering from a failed experiment.<br /><br /><pre style="color: rgb(204, 0, 0);">Public Sub FileRevertToSaved()<br /><span style=""> </span>If Len(ActiveDocument.Path) = 0 Then<br /><span style=""> </span>MsgBox "You can not revert to an unsaved file."<br /><span style=""> </span>Else<br /><span style=""> </span>If MsgBox("Are you sure that you want to abandon your current work?", vbYesNo) = vbNo Then<br /><span style=""> </span>Else<br /><span style=""> </span><span style=""> </span>Documents.Open FileName:=ActiveDocument.FullName, revert:=True<br /><span style=""> </span>End If<br /><span style=""> </span>End If<br />End Sub</pre></span>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-75283508688025511472011-05-28T07:51:00.001-07:002011-05-28T07:51:52.908-07:00Signature at foot of pageThe documents bear a signature on page 2 of a 4-page document, and we wanted to maximize the amount of white space before the signature, by pushing the signature to the foot of the signature page.<br />Place the cursor in the signature (2nd-last paragraph of page 2) and run the macro SpaceBefore.<br /><br /><pre style="color: rgb(204, 0, 0);">Sub SpaceBefore()<br />' Increase paragraph-spacing-before the first Paragraph of the selection to fill up the current page of the document<br />Dim prg As Paragraph<br />Set prg = Selection.Paragraphs(1)<br />Dim lngSpaceAbove As Long<br />lngSpaceAbove = prg.SpaceBefore<br />Dim lngPages As Long<br />lngPages = prg.Parent.Range.Information(wdActiveEndPageNumber)<br />While lngPages = prg.Parent.Range.Information(wdActiveEndPageNumber)<br /> lngSpaceAbove = lngSpaceAbove + 1<br /> prg.SpaceBefore = lngSpaceAbove<br />Wend<br />prg.SpaceBefore = lngSpaceAbove - 1<br />End Sub<br /><br />Minutes later I decided to add some text to the document, pushing the signature paragraph over to page 3, so ...<br /><br />Place the cursor in the signature (2nd-last paragraph of page 2) and run the macro DecreaseSpaceBefore.<br /><br /><pre style="color: rgb(204, 0, 0);">Sub DecreaseSpaceBefore()<br />' Decrease paragraph-spacing-before the first Paragraph of the selection to pull the current page up by one page.<br />' Use this after inserting extra text after running "IncreaseSpaceBefore"<br />Dim prg As Paragraph<br />Set prg = Selection.Paragraphs(1)<br />Dim lngSpaceAbove As Long<br />lngSpaceAbove = prg.SpaceBefore<br />Dim lngPages As Long<br />lngPages = prg.Parent.Range.Information(wdActiveEndPageNumber)<br />While lngPages = prg.Parent.Range.Information(wdActiveEndPageNumber)<br /> lngSpaceAbove = lngSpaceAbove - 1<br /> prg.SpaceBefore = lngSpaceAbove<br />Wend<br />End Sub</pre></pre>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0tag:blogger.com,1999:blog-2760334717011808819.post-92199587536652100242011-05-26T18:06:00.000-07:002011-05-26T18:11:02.097-07:00Keep with beforeDon't get me started on Microsoft ...<br />I have a simple document with "Heading 1", "Heading 2" and "Heading 3" styled paragraphs, and within each heading, text in "Body Text" style.<br />Sadly some of the Body Text material splits across a page, and I'd rather have all the Body text on the same page as its immediate parent "Heading".<br />Office 2003 hasn't had "Keep With Before" for at least the last 8 years, so I wrote the attached.<br />Use:<br />Place the text cursor anywhere in any paragraph of YOUR text style; it doesn't have to be Body Text.<br />Run the macro TESTKeepWithBeforeSelection.<br />Method:<br />I'm using Selection so you can enjoy the blinking lights.<br />I leave your original selection in place when I'm done.<br />I use the style of the FIRST paragraph in your selection as my guiding light.<br />I turn OFF KeepWithNext and turn ON KeepTogether in every paragraph in the document.<br />Then for each paragraph in your chosen style, I backup one paragraph to the preceding paragraph and turn ON KeepWithNext.<br />This seems to work for me.<br /><pre style="color: rgb(204, 0, 0);">Function KeepWithBeforeSelection(strStyle As String)<br /> Selection.HomeKey Unit:=wdStory<br /> Selection.Find.ClearFormatting<br /> Selection.Find.Style = ActiveDocument.Styles(strStyle)<br /> With Selection.Find<br /> .Text = "^p"<br /> .Replacement.Text = ""<br /> .Forward = True<br /> .Wrap = wdFindContinue<br /> .Format = True<br /> .MatchCase = False<br /> .MatchWholeWord = False<br /> .MatchWildcards = False<br /> .MatchSoundsLike = False<br /> .MatchAllWordForms = False<br /> End With<br /> While Selection.Find.Execute<br /> Selection.MoveUp Unit:=wdParagraph, Count:=2<br /> Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend<br /> With Selection.ParagraphFormat<br /> .KeepWithNext = True<br /> End With<br /> Selection.MoveDown Unit:=wdParagraph, Count:=2<br /> Wend<br />End Function<br />Sub TESTKeepWithBeforeSelection()<br /> Dim rng As Range<br /> Set rng = Selection.Range<br /> Dim strStyle As String<br /> strStyle = Selection.Paragraphs(1).Range.Style.NameLocal<br /> Selection.WholeStory<br /> With Selection.ParagraphFormat<br /> .KeepWithNext = False<br /> .KeepTogether = True<br /> End With<br /> Selection.HomeKey Unit:=wdStory<br /> Call KeepWithBeforeSelection(strStyle)<br /> rng.Select<br />End Sub<br /></pre>Under The Hoodhttp://www.blogger.com/profile/17001191718502429626noreply@blogger.com0