In order to perform this, we would require more information about what constitutes a 'word' in your record, for certainly nothing of the examples you have got quoted constitutes a phrase. If they are usually separate ranges (sentences) ended with a paragraph break up then that would end up being helpful, but without apparent sign where each 'word' starts and surface finishes it can be difficult to perform this.
Nevertheless making use of your trial as example the following will include the lines formulated with the entered word (situation sensitive) into line 1 of the excel workbook called in vivid.
Bass speaker ExtractLine
Dim oPara As Paragraph
Dim xlApp As Object
Dim xlBook As Object
Dim NextRow As Long
Dim oRng As Variety
Dim strWord As String
Const strWorkbookname As Thread = 'D:My DocumentsWorkbookName.xlsx'
strWord = InputBox('Enter word to discover')
Set oRng = ActiveDocument.Variety
With oRng.Discover
Perform While.Execute('^l')
oRng = vbCr
oRng.Fall wdCollapseEnd
Cycle
End With
On Error Application Next
Set xlApp = GetObject(, 'Excel.Software')
If Err Then
Set xlApp = CreateObject('Excel.Software')
Finish If
On Error GoTo 0
Set xlBook = xlApp.Workbooks.Open(Filename:=strWorkbookname)
xlApp.Visible = True
Set oRng = ActiveDocument.Variety
With oRng.Discover
Do While.Execute(strWord)
NextRow = xlBook.Sheets(1).Variety('A' amp; xlBook.Sheets(1).Rows.Count).Finish(-4162).Line + 1
oRng.Start = oRng.Paragraphs(1).Range.Start
oRng.Finish = oRng.Sentences(1).Range.Finish - 1
xlBook.Sheets(1).Variety('A' amp; NextRow) = oRng.Text message
oRng.Fall wdCollapseEnd
Cycle
End With
End Sub
http://www.gmayor.com/installingmacro.htm
I have a word file that I are looking for sentences with the function 'shall' in them. I have always been locating them just good, but I also want the paragraph number the sentence is discovered in. I have got the subsequent VBA code in a wórd macro. While l was preserving the information to an entry database, when I try out to open the record from accessibility it is either dangling up or too sluggish to open up, so I just did it in wórd.Nevertheless making use of your trial as example the following will include the lines formulated with the entered word (situation sensitive) into line 1 of the excel workbook called in vivid.
Bass speaker ExtractLine
Dim oPara As Paragraph
Dim xlApp As Object
Dim xlBook As Object
Dim NextRow As Long
Dim oRng As Variety
Dim strWord As String
Const strWorkbookname As Thread = 'D:My DocumentsWorkbookName.xlsx'
strWord = InputBox('Enter word to discover')
Set oRng = ActiveDocument.Variety
With oRng.Discover
Perform While.Execute('^l')
oRng = vbCr
oRng.Fall wdCollapseEnd
Cycle
End With
On Error Application Next
Set xlApp = GetObject(, 'Excel.Software')
If Err Then
Set xlApp = CreateObject('Excel.Software')
Finish If
On Error GoTo 0
Set xlBook = xlApp.Workbooks.Open(Filename:=strWorkbookname)
xlApp.Visible = True
Set oRng = ActiveDocument.Variety
With oRng.Discover
Do While.Execute(strWord)
NextRow = xlBook.Sheets(1).Variety('A' amp; xlBook.Sheets(1).Rows.Count).Finish(-4162).Line + 1
oRng.Start = oRng.Paragraphs(1).Range.Start
oRng.Finish = oRng.Sentences(1).Range.Finish - 1
xlBook.Sheets(1).Variety('A' amp; NextRow) = oRng.Text message
oRng.Fall wdCollapseEnd
Cycle
End With
End Sub
http://www.gmayor.com/installingmacro.htm
Extract sentences containing a specific word to excel file Extracts each sentence with the word 'shall' in a Word Document to a new line in an Excel File VBA Express: Word - Extract sentences containing a specific word to excel file.
What are I performing wrong? It works sometimes. Occasionally it does not get a quantity, other situations it will get the incorrect paragraph.
Place db = 0penDatabase('d:é2drtmdb.mdb')
Sentenceform.Present
Place rsRec = db.0penRecordset('RequirementsTable', dbOpenDynaset, dbSéeChanges)
Place aRange = ActiveDocument.Variety
intCount = 1
With aRange.Discover
Perform
.Text message = 'shall' ' the word I feel looking for
.Exécute
If.Found After that
aRange.Expand Unit:=wdSentence
aRange.Copy
aRange.Break wdCollapseEnd
Séntenceform!SentenceField = '
Séntenceform!SentenceField.Insert
'obtain the area?
strSection = aRangé.ListFórmat.ListString
lf Len(strSection) It; 1 After that strSection = 'In/A'
rsRéc.AddNew
rsRéc!sentence = Sentenceform!SentenceField.Worth
rsRec!paragraphnumbér = strSection
rsRéc.Revise
Finish If
Loop While.Found
Finish With