View Single Post
 
Old 04-16-2019, 05:22 PM
one4youman one4youman is offline Windows 7 32bit Office 2010
Novice
 
Join Date: Apr 2019
Posts: 4
one4youman is on a distinguished road
Default

Unfortunately I do not think I can do it that way due to the specific way the contracts are written as I cannot change how they currently appear within the template for compliance reasons.

What I could however do is highlight the portion of the term and then somehow use Selection.Find to extract the highlighted text then pass to the caption. Once the form has been completed and all Bookmarks are update based on the UserForm, I would execute another sub to clear any yellow highlighted text from the document.

I have been trying to figure out how to get the below to do this but cannot seem to figure out a good solution.

Code:
    Dim bmk As Bookmark
    Dim i As Long
    Dim P As String
    Dim CovOutput As String
    Dim msg As String
        i = 1
        For Each bmk In ActiveDocument.Bookmarks("Contract1").Range.Bookmarks
            
            '*************************
            'Find the highlighted text
            '*************************
            
                If BkMkCount = 1 Then
                    With Selection.Bookmarks(1)
                        BkMkName = .Name
                        .Select
                       
                       With Selection.Find
                        .ClearFormatting
                        .Replacement.ClearFormatting
                        .Text = ""
                        .MatchWildcards = False
                        .Forward = True
                        .Wrap = wdFindContinue
                        .Highlight = True
                        Do
                            .Execute
                        Loop Until Selection.Range.HighlightColorIndex = wdYellow _
                          Or Not .Found
                        HighlightedText = Selection.Range '.Select
                    End With
                    MsgBox msg
                       MsgBox BkMkName
                    End With
                End If
            '*************************
            
            
            CovOutput = bmk.Name
            P = i
            
            Controls("CheckBox" & P).Tag = bmk.Name 'Set Tag equal to the bookmark name - Extract Tag to determine which to remove on false statement.
            Controls("CheckBox" & P).Caption = HighlightedText 'Highlighted text located within the bookmark.
            Controls("CheckBox" & P).ControlTipText = Mid(ActiveDocument.Bookmarks(CovOutput).Range.Text, (InStr(ActiveDocument.Bookmarks(CovOutput).Range.Text, ".") + 1)) 'Remaining text from the string
                msg = msg & bmk.Name & vbCr 'Adds bookmark names to Msgbox to use during debug.
                    
            i = (i + 1)
            On Error GoTo ErrorStop
        Next bmk
ErrorStop:
    
    'Uncomment for Debug
    'MsgBox msg
End Sub


Thanks,
John

Reply With Quote