Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 04-16-2019, 05:22 PM
one4youman one4youman is offline Extract Bold text from string Windows 7 32bit Extract Bold text from string Office 2010
Novice
Extract Bold text from string
 
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
 

Tags
bold, extract, string

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula to Extract text from a text string Haha88 Excel 2 11-14-2017 01:32 AM
Extract Bold text from string Extract text from a text string Haha88 Excel 8 02-13-2017 05:06 PM
Extract Bold text from string Extract a string from a paragraph kirkm Word VBA 7 09-11-2016 06:13 PM
Extract numbers from a text string aleale97 Excel 4 02-10-2011 10:33 AM
Extract from String using Wildcard whousedmy Word 0 05-21-2009 01:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft