Take all underlined words, put in Excel column

I have a 100+ page Word document, that I would like to extract all of the underlined words from. I am very familiar with VBA and Excel, but relatively new to Word. I was wondering if this is the best way to do what I'm trying.

I will run this from my Word document:

Sub extractUnderlinedWords() Dim thisDoc As Word.Document Application.ScreenUpdating = False Dim appExcel As Object, oxlWbk As Object Dim FN      As String Dim aRange  As Range Dim intRowCount As Integer intRowCount = 1  Set thisDoc = ActiveDocument Set aRange = thisDoc.Range  Set appExcel = CreateObject("Excel.application") FN = "C:\Users\[blah]\UnderlinedWords.xlsx"  If FileExists(FN) Then     Set oxlWbk = appExcel.workbooks.Open(fileName:=FN).Sheets("Sheet1") End If  With aRange.Find     Do         .Font.Underline = True         .Execute         If .Found Then             '   aRange.Expand Unit:=wdSentence             '      aRange.Select             If Len(aRange) > 1 Then                 If Not aRange.InRange(thisDoc.TablesOfContents(1).Range) Then                     aRange.MoveEndWhile cset:=Chr(13), Count:=wdBackward                     '    aRange.Copy                     oxlWbk.Cells(intRowCount, 1).Value = aRange.Text                     aRange.Collapse wdCollapseEnd                     Debug.Print "Page: " & aRange.Information(wdActiveEndAdjustedPageNumber)                     '    aRange.Select                     If oxlWbk Is Nothing Then                         intRowCount = 1                     End If                     'oxlWbk.Cells(intRowCount, 1).Value = aRange.Text                     ' oxlWbk.Paste                     intRowCount = intRowCount + 1                 End If             End If         End If     Loop While .Found End With If Not oxlWbk Is Nothing Then     appExcel.workbooks(1).Close True     appExcel.Quit     Set oxlWbk = Nothing     Set appExcel = Nothing End If Set aRange = Nothing Application.ScreenUpdating = True MsgBox ("Done!") End Sub 

This does work, but after about page 14, it hangs up and "freezes" on me. Pressing CTRL+BREAK does nothing, except "unfocus" the application.

Should I instead, add all found words to an Array, then after it's done scanning the Word document, focus on Excel and outputting the parts of array row by row? I think perhaps what's causing the freeze is the jumping back and forth from Word to Excel. (Or, could it be that I'm using a Do/While loop?)

Again, the idea is to take all underlined words and put in an Excel sheet for reviewing.

Edit: I'm not married to the Excel idea. In the end I need it in Excel, but if there are other ideas (perhaps send data to .txt first, then open in Excel), I'm open to them!

Edit2: Following this answer, I tried creating a .txt file to do the same. It does work, as expected, but again, hangs up Word after about 4 pages. I've left it running for 10 minutes, and it isn't complete...

Edit3: I tried keeping this all within Word. I created a String Array, and when I found an underlined word, I just added that word to the array. However, this also gets to a point where it fails and just freezes.

Replay

In the Word document

  1. Click on an underlined word
  2. In the Home menu, in the Editing section, click Select > Select Text with Similar Formatting
  3. Copy
  4. Open Excel and paste

You may need to clean it up in Excel, but you don't need VBA to do this.

Take all underlined words, put in Excel column

Category: vba Time: 2016-07-28 Views: 0

Related post

  • how to add 8:00:00 hours to all the datetime values in a column in MS Excel sheet 2010-09-30

    Need a syntax for building up a formula to add 8:00:00 hours to all the datetime values in a column in MS Excel sheet. Using Sum() Function doesn't work. --------------Solutions------------- Method 1: New values in another column Assuming you have a

  • Word mail merge using excel column to select layout from other documents 2014-02-06

    I have about 30 word documents. There is 1 document that is the main one setup to use for mail merge. There is a column in the recipiant list that is meant to select the document that will be used for that row. so for example there is a column that l

  • Combining all combinations of data from mutiple columns in Excel 2015-05-06

    I am looking at this code Mr. Fedorov provided on November 5, 2014: Combining all combinations of data from three columns in excel It is doing what I expect it to do, but my range appears to be too large, because I get the Run-time error '1004'. Is t

  • Make last column take all remaining space in longtable 2015-05-21

    I want to create a table using longtable where all columns have a fixed length except the last one, which should take all remaining space. The table itself should be full page width. I tried the following with longtable, but it is not working: \docum

  • Split copy from non-adjoining Excel columns to non-adjoining Word table columns 2016-01-21

    Would like to copy three ranges of data from Excel and then paste the three different ranges in an existing Word table. The Word document is generated from another program and the file name is different each time. I need to split the three ranges up

  • Excel column label from integer 2013-06-23

    I would like to create a function in Mathematica, which returns the equivalent Excel column label (e.g., A, Z, AA, AZ, and so on) given a column number. I think it can be done with IntegerString[10,26], but this representation set of this chars is 0

  • Insert/Display Two-Page Word Object in Excel Sheet 2014-02-13

    I've trying to take a two-page Word doc and insert it into an Excel 2010 worksheet. I'm not trying to link to the original document. So far I've been able to insert the object, but it only displays the first page. To see the second page, I have to do

  • Searching a Word Document from Excel - v2.0 2014-09-16

    My first question: Searching a Word Document from Excel Since then I have implemented most of the suggestions by @RubberDuck and @Comintern. I have also added functionality for different-sized spreadsheets (horizontal and vertical), read multiple fil

  • Reading info from word, calculating in excel, and posting back in word 2016-02-04

    I am pretty new to VBA and I am having a hard time understanding how I can do what I need to do. Before me our team looked at the data in a cell in word went to an excel file found which sheets were affected then wrote them all into word. I have chan

  • Extract address from Word document into Excel or CSV 2013-03-27

    I have a Word file with about 8,000 standard letters in it, which start with standard opening date: 26 March 2013 XXXfew lines addressXXX Dear Name paragraphs. I like to extract the address in CSV or Excel format. Any idea how? I am not good in macro

  • How to filter an array of words in Microsoft Excel? 2013-11-08

    This question already has an answer here: How can I filter data based on items in a list? 2 answers How do I filter an array of words in Microsoft Excel? For example, I have a big list of road names in Singapore and I wish to filter all entries in th

  • Copy data from multiple MS Word files to Excel using VBA 2014-06-29

    I know this question was already asked (Copying data from multiple word docs into one excel sheet) the thing is I can't use the answer. I'm fresh to VBA, but I thought I can handle it. I was wrong. I was trying to use the code provided in the mention

  • finding all the words in a text file appearing in another text file 2015-12-12

    Suppose I have two files a.txt and b.txt. I want to find all the words in a.txt which appear in b.txt. Is there a specific command to do that? --------------Solutions------------- With bash, zsh and some implementations of ksh: comm -12 <(tr -s '[:sp

  • Parse Excel Column, First Name ( optional )Middle, Last name into 3 columns? 2010-07-20

    How do you parse Excel Column, First Name ()Middle, Last name into 3 columns? Ivan P. Freely Jordan Smith How would you parse the above Excel column list of full names into 3 distinct columns with first, middle, last name when the middle name may not

  • How can I click on the 'underlined words' in the rules dialog box for Outlook 2007? 2010-12-02

    I am trying to create a rule in Outlook 2007 in my Windows 7 (64 bit) machine. I am unable to click on the underlined word shown in the dialog box below. The problem is that either the dialog box is getting cut-off or the underlined word is not worki

  • makeindex page entries are all underlined 2011-02-16

    Set up an index for a book and everything works well, except the page numbers listed for the words in the Index are all underlined---EXCEPT when I add bold face, then they look fine. Any ideas what the problem is? Thanks! Okay, here it is: \documentc

  • Finding all dictionary words that can be made with a given set of characters (Wordfeud/Scrabble) 2012-05-03

    This is a slightly more involved variant of this recent question. By sheer coincidence I happened to have been building a Wordfeud (Scrabble clone) game in Mathematica. My interactive Wordfeud board in Mathematica I used DictionaryLookup with StringE

  • Cannot open word document and Excel from Sharepoint 2010 2012-10-22

    I am not able to open any word documents and Excel from my Sharepoint2010 sites. I was able to open them before I re-installed everything from scratch. When I try and open any uploaded Excel document it says: "The workbook cannot be opened" (wit

  • Take all the bits in a number and shift them to the left end 2013-09-03

    I wrote this program which takes all the bits in a number and shifts them to the left end (for example: 01010110 --> 11110000). It's and exercise from a book. It works, but it seems to be very wasteful to use integers (I only need 8 bits). Can you te

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.124 (s). 13 q(s)