![]() |
|
#1
|
|||
|
|||
![]()
For a common process, you could make the docCurrent a module level variable and then pass arguments to:
Code:
Sub ProcessTable(oTbl As Table, strStartWord As String, strEndWord As String, strUser As String) Dim oRng As Row Dim strKeyword As String, strRule As String For Each oRow In oTbl.Rows strKeyword = Split(Trim(oRow.Range.Cells(1).Range.Text), vbCr)(0) strRule = Split(Trim(oRow.Cells(2).Range.Text), vbCr)(0) If strKeyword <> "" Then Set oRng = GetDocRange("DETAILED", "CLAIMS") 'make docCurrent a module level varialbe Set oRngScope = oRng.Duplicate With oRng.Find .Text = strKeyword Do While .Execute If Not oRng.InRange(oRngScope) Then Exit For oRng.HighlightColorIndex = wdTurquoise If strRule <> "" Then Set cmtRuleComment = m_oDocCurrent.Comments.Add(Range:=oRng, Text:=strUser & ": " & strRule) cmtRuleComment.Author = UCase("WordCheck") cmtRuleComment.Initial = UCase("WC") End If Loop End With End If Next oRow End Sub Function GetDocRange(startWord As String, endWord As String) As Range Dim oRng As Word.Range, iStart As Long, iEnd As Long Set oRng = m_oDocCurrent.Range With oRng.Find .Text = startWord If .Execute Then iStart = oRng.End oRng.End = aDoc.Range.End .Text = endWord If .Execute Then iEnd = oRng.Start If startWord = "ABSTRACT" Then iEnd = aDoc.Range.End If iEnd > iStart Then Set GetDocRange = aDoc.Range(iStart, iEnd) End If End With End Function |
#2
|
|||
|
|||
![]()
Ok, I may be in over my head. Here is the concept of what I am attempting, but failing, to do.
I have a UserForm that has 6 toggle buttons and a command button. Each toggle button corresponds to one of the possible sections in the document, which are the words passed to GetDocRange as startWord and endWord. The idea is to click the toggle buttons for the sections that are in a given document and then click the command button to close the UserForm and continue with execution of the macro. Based on which toggle buttons are set to true, corresponding variables should be set to true. Based on the values of those variables, startWord and endWord should be provided. For example, the possible sections as represented by the toggle buttons are Background, Summary, Drawing, Description, Claim, and Abstract. If all sections are present, the code should progress through a first loop with startWord = Background and endWord = Summary, a second loop with startWord = Summary and endWord = Drawing, etc. When startWord is Abstract, endWord should also be Abstract. However, if all sections are not present, that section should be skipped. For example, assume that Summary is not present in some given document. In that case, the toggle buttons for all sections other than Summary are toggled true and the code should progress through a first loop with startWord = Background and endWord = Drawing, a second loop with startWord = Drawing and endWord = Description, etc. When startWord is Abstract, endWord should again be Abstract. I have ToggleButtonX_Change routines for each toggle button in the UserForm that chack whether the button value is true or false, but I'm having trouble figuring out where to stick the variables (and what type they should be) for the loop, as well as figuring out how to set up the loop to do the skips as I described. My thought is some sort of For loop with the index used for the table number as well as selecting which of the section names to use for startWord and endWord, but that's a half-baked thought that I can't seem to round out into an outline for coding. The second thought was combining the For loop and index with a select case statement to evaluate the various possible outcomes, but that thought didn't get much farther than the first. I'm open to any suggestions or advice, and thanks in advance. |
#3
|
|||
|
|||
![]()
I've also run into an interesting new issue where docRef.Tables.Count is returning a value of 2 when in fact there are 7 tables in docRef.
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
jmcsa3 | Excel Programming | 1 | 05-02-2020 06:56 AM |
![]() |
Triadragon | Excel | 3 | 05-02-2016 11:48 AM |
Find a Date in a Range | rspiet | Excel | 3 | 02-15-2016 08:37 AM |
find IP in range / find number between numbers | gn28 | Excel | 4 | 06-14-2015 03:46 PM |
Find and Replace within range | anil3b2 | Word VBA | 3 | 12-01-2010 02:35 AM |