|
Visual Basic (VB6 and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Visual Basic Library
This page was last updated on Saturday, November 24, 2001
Public Function AddStyleToTable(varStyleRanges(), strStylename) ' Procedure : AddStyleToTable ' Description: Append a set of ranges for all occurrences of the named style. ' By: Chris Greaves Inc. ' Inputs: Variant array (style/range), STRING style name. ' Returns: None. ' Assumes: Nothing ' Side Effects: The selection point may change. ' Tested: By the calls below. Dim intUbound As Integer ' Upper limit of our table, incremented for each success intUbound = UBound(varStyleRanges, 2) ' Assumes current selection point as origin. ' I should switch to ranges, I know how to use them now. ' You may elect to include a return to top-of-document at the start of a search. Selection.Find.ClearFormatting Selection.Find.Style = ActiveDocument.Styles(strStylename) With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With While Selection.Find.Execute intUbound = UBound(varStyleRanges, 2) varStyleRanges(0, intUbound) = strStylename varStyleRanges(1, intUbound) = Selection.Range.Start varStyleRanges(2, intUbound) = Selection.Range.End ReDim Preserve varStyleRanges(2, intUbound + 1) Wend Selection.Find.ClearFormatting ' Note that after a successful serach, the array ought to be redimensioned: 'Sub TESTAddStyleToTable() 'Dim varAr() 'ReDim varAr(2, 0) 'Call AddStyleToTable(varAr, "heading 2") ' Note case-insnsitive search. 'Call AddStyleToTable(varAr, "Text 2") 'Call AddStyleToTable(varAr, "Normal") 'End Sub End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Monday, November 19, 2001 |