Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 22,467
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
 



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 02:50 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