none
Transferring all the underlined words

    Question

  • Hi,
    I have a problem with underlined words. I have 400 pages word document.
    and some of words are underlined. I want to transfer all the underlined words to another word document or to the end of current document.

    Is there any solution for this??

    thankss
    Friday, August 20, 2010 8:39 AM

Answers

  • Hi swem

    You don't provide a lot of information about what this document contains in the way of tables, or graphics that may have underlined text, or underlined text in headers, footers, etc. Any of that complicates things appreciably.

    But here's the basic code for a document with none of those things

    Sub TransferUnderlinedWords()
      Dim docSource As Word.Document
      Dim docNew As Word.Document
      Dim rngSearch As Word.Range
      Dim rngContent As Word.Range
      Dim rngTarget As Word.Range
      Dim bFound As Boolean
      
      Set docSource = ActiveDocument
      Set rngContent = docSource.Content
      Set rngSearch = rngContent.Duplicate
      
      Set docNew = Documents.Add
      Set rngTarget = docNew.Content
      
      'Set the find criteria
      With rngSearch.Find
        .ClearFormatting
        .Text = ""
        .Replacement.ClearFormatting
        .Replacement.Text = ""
        .Font.Underline = wdUnderlineSingle
      End With
      Do
        bFound = rngSearch.Find.Execute
        If bFound Then
          'rngSearch will contain the underlined text
          'If you don't want the underlining to be copied
          'use .Text instead of .FormattedText
          rngTarget.FormattedText = rngSearch.FormattedText
          rngTarget.Collapse wdCollapseEnd
          rngTarget.Text = vbCr
          'The next entry will be on a new line
          rngTarget.Collapse wdCollapseEnd
          
          rngContent.Start = rngSearch.End + 1
          rngSearch.Collapse wdCollapseEnd
        End If
      Loop While bFound
    End Sub
    
    

    Cindy Meister, VSTO/Word MVP
    Friday, August 20, 2010 1:06 PM
    Moderator
  • yes I have solved this problem. Ms word has a option like this. 

    I have used  Find Dialog to solve this.

    Find Dialog > Format : underline 

    then it finds all underlined words in the document then you can copy all of them to another document.

    thanks a lot,

    Best regards...

     

     

    Thursday, August 26, 2010 7:05 AM

All replies

  • Hi swem

    You don't provide a lot of information about what this document contains in the way of tables, or graphics that may have underlined text, or underlined text in headers, footers, etc. Any of that complicates things appreciably.

    But here's the basic code for a document with none of those things

    Sub TransferUnderlinedWords()
      Dim docSource As Word.Document
      Dim docNew As Word.Document
      Dim rngSearch As Word.Range
      Dim rngContent As Word.Range
      Dim rngTarget As Word.Range
      Dim bFound As Boolean
      
      Set docSource = ActiveDocument
      Set rngContent = docSource.Content
      Set rngSearch = rngContent.Duplicate
      
      Set docNew = Documents.Add
      Set rngTarget = docNew.Content
      
      'Set the find criteria
      With rngSearch.Find
        .ClearFormatting
        .Text = ""
        .Replacement.ClearFormatting
        .Replacement.Text = ""
        .Font.Underline = wdUnderlineSingle
      End With
      Do
        bFound = rngSearch.Find.Execute
        If bFound Then
          'rngSearch will contain the underlined text
          'If you don't want the underlining to be copied
          'use .Text instead of .FormattedText
          rngTarget.FormattedText = rngSearch.FormattedText
          rngTarget.Collapse wdCollapseEnd
          rngTarget.Text = vbCr
          'The next entry will be on a new line
          rngTarget.Collapse wdCollapseEnd
          
          rngContent.Start = rngSearch.End + 1
          rngSearch.Collapse wdCollapseEnd
        End If
      Loop While bFound
    End Sub
    
    

    Cindy Meister, VSTO/Word MVP
    Friday, August 20, 2010 1:06 PM
    Moderator
  • Hi swemshut,

    How is this issue going on in your side? Have you solved the problem?

    Best Regards,
    Amy Li
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Thursday, August 26, 2010 1:57 AM
    Moderator
  • yes I have solved this problem. Ms word has a option like this. 

    I have used  Find Dialog to solve this.

    Find Dialog > Format : underline 

    then it finds all underlined words in the document then you can copy all of them to another document.

    thanks a lot,

    Best regards...

     

     

    Thursday, August 26, 2010 7:05 AM