I'm trying to find the first two dates in a Word document save them as variables in an Excel macro. Other parts of my project require this to be written as an Excel macro.
Dim wordObj As New Word.Application
Dim wordDoc As New Word.Document
Dim Rng As Range
Dim myDate As String
Dim Fnd As Boolean
Dim i As Long
i=0
Set wordDoc = wordObj.Documents.Open(path)
Set Rng = wordDoc.Range
Do While i < 2
With Rng.Find
.Execute FindText:="??/??/????", MatchWildcards:=True
Fnd = .Found
End With
If Fnd = True Then
mydate = Rng
If i = 0 Then
firstdate = mydate
ElseIf i = 1 Then
seconddate = mydate
End If
End If
i = i+1
Loop
End Function
I get Compile Error: Argument not optional. The issue is, VBA is interpreting it as Excels' .Find with arguments(Target, StartLine, StartColumn... etc), instead of a Word Find object. I am new to VBA, and managing the different types of applications is a little confusing.