debkev1010
03-05-2008, 08:48 AM
I'm writing some code to search for a certain word in a Word document. When I find the word, I select the sentence and paste it into an excel spreadsheet -
for sentenceCount = 1 to worddoc.sentences.count
doctext = worddoc.sentences.item(sentencecount).text
if instr(1, doctext, "Fred") <> 0 then
activesheet.cells(rowIndex, 1).value = doctext
rowindex = rowindex+1
end if
next
The only problem is when I find "Fred" in a sentence with a colon followed by a bulleted or numbered list, the code above is only selecting up to the colon, leaving out the list when it copies to the excel file. In the Word document after each colon is a carriage return and after each item in the list there's a carriage return. In the Word document I've followed a standard format with these list in that I place a period at the end of the last item in the list (to complete the sentence). Evidently, Word doesn't recognize the list as part of the sentence (when I turn on the paragraph marker, there's a marker next to the colon and a marker at the end of each item in the list). I'm looking for a solution that will either tell Word that the list is part of the preceeding sentence or VBA code that will also select the list with the preceeding sentence.
Thanks,
Kevin
for sentenceCount = 1 to worddoc.sentences.count
doctext = worddoc.sentences.item(sentencecount).text
if instr(1, doctext, "Fred") <> 0 then
activesheet.cells(rowIndex, 1).value = doctext
rowindex = rowindex+1
end if
next
The only problem is when I find "Fred" in a sentence with a colon followed by a bulleted or numbered list, the code above is only selecting up to the colon, leaving out the list when it copies to the excel file. In the Word document after each colon is a carriage return and after each item in the list there's a carriage return. In the Word document I've followed a standard format with these list in that I place a period at the end of the last item in the list (to complete the sentence). Evidently, Word doesn't recognize the list as part of the sentence (when I turn on the paragraph marker, there's a marker next to the colon and a marker at the end of each item in the list). I'm looking for a solution that will either tell Word that the list is part of the preceeding sentence or VBA code that will also select the list with the preceeding sentence.
Thanks,
Kevin