alwayshouston
MIS
Hi All
I am seeking help to edit my code that finds the word "Status" in a MS Word file controlling from Excel. Once it finds word "status" by itself in the word document, it copies the rest of page and paste it to excel. I have successfully written the code, but my find does not go to next word "status". It simply gets stuck on the first find. Below is my code. Please help me to edit below code.
Thanks in Advance!
Sub CopyFromWord()
Dim wrd As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Set wrd = CreateObject("Word.Application")
wrd.Visible = True
Application.ScreenUpdating = False
'copy open word document to Excel
With Range("A1")
.Formula = "Word Document Contents:"
.Font.Bold = True
.Font.Size = 14
.Offset(1, 0).Select
End With
r = 3 ' startrow for the copied text from the Word document
wrd.Visible = False
wrd.Documents.Open "C:\Foldername\MyNewWordDoc.doc"
Set wrdDoc = wrd.Documents("MyNewWordDoc.doc")
Do Until wrdDoc.Bookmarks("\Sel") = _
wrdDoc.Bookmarks("\EndOfDoc")
wrd.Selection.Find.ClearFormatting
With wrd.Selection.Find
.Text = "Status"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wrd.Selection.Find.Execute
If wrd.Selection.Find.Found = True Then
wrd.Selection.EndKey Unit:=wdLine, Extend:=wdExtend
wrd.Selection.HomeKey Unit:=wdLine
wrd.Selection.EndKey Unit:=wdLine, Extend:=wdExtend
'Checking whether if it is only STATUS in the line
StatusCheck = wrd.Selection.Text
If Trim(StatusCheck) = "Status" Then
' Select the end of the page
wrd.Selection.MoveDown
wrd.Selection.HomeKey Unit:=wdLine
wrd.Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Set tRange = wrd.Selection.Range
tRange.SetRange Start:=tRange.Start, End:=wrdDoc.Bookmarks("\Page").Range.End
tString = tRange.Text
ActiveSheet.Range("A" & r).Formula = tString
r = r + 1
End If
Else
Exit Do
End If
Loop
wrd.Quit
Set wrd = Nothing
End Sub
I am seeking help to edit my code that finds the word "Status" in a MS Word file controlling from Excel. Once it finds word "status" by itself in the word document, it copies the rest of page and paste it to excel. I have successfully written the code, but my find does not go to next word "status". It simply gets stuck on the first find. Below is my code. Please help me to edit below code.
Thanks in Advance!
Sub CopyFromWord()
Dim wrd As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Set wrd = CreateObject("Word.Application")
wrd.Visible = True
Application.ScreenUpdating = False
'copy open word document to Excel
With Range("A1")
.Formula = "Word Document Contents:"
.Font.Bold = True
.Font.Size = 14
.Offset(1, 0).Select
End With
r = 3 ' startrow for the copied text from the Word document
wrd.Visible = False
wrd.Documents.Open "C:\Foldername\MyNewWordDoc.doc"
Set wrdDoc = wrd.Documents("MyNewWordDoc.doc")
Do Until wrdDoc.Bookmarks("\Sel") = _
wrdDoc.Bookmarks("\EndOfDoc")
wrd.Selection.Find.ClearFormatting
With wrd.Selection.Find
.Text = "Status"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wrd.Selection.Find.Execute
If wrd.Selection.Find.Found = True Then
wrd.Selection.EndKey Unit:=wdLine, Extend:=wdExtend
wrd.Selection.HomeKey Unit:=wdLine
wrd.Selection.EndKey Unit:=wdLine, Extend:=wdExtend
'Checking whether if it is only STATUS in the line
StatusCheck = wrd.Selection.Text
If Trim(StatusCheck) = "Status" Then
' Select the end of the page
wrd.Selection.MoveDown
wrd.Selection.HomeKey Unit:=wdLine
wrd.Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Set tRange = wrd.Selection.Range
tRange.SetRange Start:=tRange.Start, End:=wrdDoc.Bookmarks("\Page").Range.End
tString = tRange.Text
ActiveSheet.Range("A" & r).Formula = tString
r = r + 1
End If
Else
Exit Do
End If
Loop
wrd.Quit
Set wrd = Nothing
End Sub