Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-01-2015, 09:54 AM
rfaris rfaris is offline Copy Underline text from Word and Paste into excel Windows 7 64bit Copy Underline text from Word and Paste into excel Office 2010 64bit
Novice
Copy Underline text from Word and Paste into excel
 
Join Date: Oct 2015
Posts: 4
rfaris is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 10-01-2015, 04:00 PM
macropod's Avatar
macropod macropod is offline Copy Underline text from Word and Paste into excel Windows 7 64bit Copy Underline text from Word and Paste into excel Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 10-02-2015, 07:04 AM
rfaris rfaris is offline Copy Underline text from Word and Paste into excel Windows 7 64bit Copy Underline text from Word and Paste into excel Office 2010 64bit
Novice
Copy Underline text from Word and Paste into excel
 
Join Date: Oct 2015
Posts: 4
rfaris is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 10-02-2015, 01:49 PM
macropod's Avatar
macropod macropod is offline Copy Underline text from Word and Paste into excel Windows 7 64bit Copy Underline text from Word and Paste into excel Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 10-04-2015, 04:10 PM
rfaris rfaris is offline Copy Underline text from Word and Paste into excel Windows 7 64bit Copy Underline text from Word and Paste into excel Office 2010 64bit
Novice
Copy Underline text from Word and Paste into excel
 
Join Date: Oct 2015
Posts: 4
rfaris is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 10-04-2015, 04:39 PM
macropod's Avatar
macropod macropod is offline Copy Underline text from Word and Paste into excel Windows 7 64bit Copy Underline text from Word and Paste into excel Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 10-04-2015, 08:25 PM
macropod's Avatar
macropod macropod is offline Copy Underline text from Word and Paste into excel Windows 7 64bit Copy Underline text from Word and Paste into excel Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #8  
Old 10-05-2015, 05:56 AM
rfaris rfaris is offline Copy Underline text from Word and Paste into excel Windows 7 64bit Copy Underline text from Word and Paste into excel Office 2010 64bit
Novice
Copy Underline text from Word and Paste into excel
 
Join Date: Oct 2015
Posts: 4
rfaris is on a distinguished road
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Underline text from Word and Paste into excel 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 Underline text from Word and Paste into excel Copy/Paste EXCEL cells as pic in WORD A_Lau Drawing and Graphics 3 12-19-2014 06:57 AM
Copy Underline text from Word and Paste into excel 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:18 AM.


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