#1
|
|||
|
|||
Copy Underline text from Word and Paste into excel
I need to search through all Word Documents in a folder looking for each underlined phrase. I then want to copy that phrase and paste it in an Excel spreadsheet along with the document name that the phrase came from. I am new to Word Macros. can someone help? |
#2
|
||||
|
||||
The following macro runs a Word session so that underlined content in Word documents in the selected folder can be extracted from all documents in that folder.
Code:
Sub GetWordData() 'Note: this code requires a reference to the Word object model, 'added via Tools|References in the Excel VBE Application.ScreenUpdating = False Dim wdApp As New Word.Application Dim wdDoc As Word.Document Dim StrFolder As String, StrFile As String Dim WkSht As Worksheet, i As Long, j As Long StrFolder = GetFolder If StrFolder = "" Then Exit Sub Set WkSht = ActiveSheet i = WkSht.Cells(WkSht.Rows.Count, 1).End(xlUp).Row StrFile = Dir(StrFolder & "\*.docx", vbNormal) While StrFile <> "" Set wdDoc = wdApp.Documents.Open(Filename:=StrFolder & "\" & StrFile, AddToRecentFiles:=False, Visible:=False) With wdDoc With .Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "" .Replacement.Text = "" .Wrap = wdFindStop .Forward = True .Format = True .Font.Underline = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute End With Do While .Find.Found i = i + 1 WkSht.Cells(i, 1).Value = StrFile WkSht.Cells(i, 2).Value = .Text If .End = wdDoc.Range.End Then Exit Sub .Collapse wdCollapseEnd .Find.Execute Loop End With .Close SaveChanges:=False End With StrFile = Dir() Wend wdApp.Quit Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Macropod,
This works well, but it did not respond with all of the documents in the folder. I noticed that only the ".docx" files were checked. I changed the following line to: StrFile = Dir(StrFolder & "\*.doc*", vbNormal). It was: StrFile = Dir(StrFolder & "\*.docx", vbNormal). That worked to allow documents ending with ".docm" and ".doc", but there are still some that are missing and I cannot determine the reason. |
#4
|
||||
|
||||
If you change 'docx' to 'doc, it will pick up doc, docx and docm documents. As for the skipped document, do they have some forma of protection?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Changing to "*.doc" works great. However, there are still some documents that it does not open. I checked for any protection but could not find anything.
|
#6
|
||||
|
||||
OK, some detective work will be needed. For example, what is their document format (doc, docx, docm)? If doc, do they contain macros? Is the unprocessed content in the body of the document, or in textboxes, footnotes, etc.?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
||||
|
||||
Cross-posted at: http://www.mrexcel.com/forum/excel-q...nto-excel.html
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184 I wonder whether (or when) you intended to let people in both forums know you had them doing effectively the same work??? Or maybe you just enjoy wasting other peoples' time...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
I apologize. After I had posted in the other forum, I found this forum. This forum deals more with all aspects of MS Office. I thought because my problem deals with Word as well as Excel that it was the better choice. There was no malice intended. I withdraw my request for help from this forum, ask that you accept my apology.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Copy/paste from Excel to Word problems! | mross127 | Word | 10 | 08-16-2017 04:41 PM |
Copy Text Twice to Paste into word | Albundy | Word | 2 | 09-02-2016 12:59 PM |
Copy/Paste EXCEL cells as pic in WORD | A_Lau | Drawing and Graphics | 3 | 12-19-2014 06:57 AM |
Copy Paste Serial No to Excel in Text format | linan123 | Excel | 1 | 05-02-2014 07:50 PM |
copy/paste charts from excel to word | bielak01 | Excel | 0 | 04-16-2009 02:27 AM |