I've got the following text in word:
R.L/I.L.(S.L) METERS. RAIL/FLOOD LEVEL: ___ . No. TRACKS: 2
TRACK ALIGNMENT: CURVE. SUPER'N:________________ GUARD RAILS: YES / NO_______________
SPANS: 1 X 1.2 X 50 METER BRICK ARCH CULVERT
DRAWING: ______________LOAD RATING: ________________ LOAD/CLEAR. SIGNS: _______________________
I need to find the word SPANS and select the rest of the like after the ":" and copy that to an excel cell.
I have a number of these search/copy to do.
The main code is in Excel, opening word document and then finding the stuff to paste back into excel.
R.L/I.L.(S.L) METERS. RAIL/FLOOD LEVEL: ___ . No. TRACKS: 2
TRACK ALIGNMENT: CURVE. SUPER'N:________________ GUARD RAILS: YES / NO_______________
SPANS: 1 X 1.2 X 50 METER BRICK ARCH CULVERT
DRAWING: ______________LOAD RATING: ________________ LOAD/CLEAR. SIGNS: _______________________
I need to find the word SPANS and select the rest of the like after the ":" and copy that to an excel cell.
I have a number of these search/copy to do.
The main code is in Excel, opening word document and then finding the stuff to paste back into excel.
Code:
Set wd = CreateObject("Word.Application")
wd.Visible = False
Dim i As Integer
i = 1
Range("filename").Select
Selection.Offset(i, 0).Select
If Right(Selection.Value, 3) = "doc" Or Right(Selection.Value, 3) = "rtf" Then
Application.StatusBar = "Opening File " & Selection.Value
filename1 = Selection.Value
wd.Documents.Open Filename:=filename1
wd.Visible = True
wd.Selection.GoTo What:=wdGoToLine, Which:=wdGoToRelative, Count:=1
Set strFoundSpans = Nothing
With wd.Selection.Find
.ClearFormatting
.Text = "SPANS"
.Execute
strFoundSpans = wd.Selection.Text
If Not IsEmpty(strFoundSpans) Then
wd.Visible = True
wd.Selection.MoveRight Count:=3, Extend:=wdMove
wd.Selection.EndKey Extend:=wdExtend
strFoundSpansText = Selection.Text
Range("spans").Select
Selection.Offset(i, 0).Select
Selection.Value = strFoundSpansText
End If
End With