Hi guys,
I am trying to develop a code in Excel VBA that will collect all the data gathered through a Userform and then Find and Replace all that information in a dummy contract.
I have succesfully programmed all the Excel part of this process, however from some reason I cannot get Excel to Find and Replace in the Word document I specify.
Here's the code I have thus far for this bit of the process:
Sub Test()
Dim Nationality As String
Nationality = "Mexican"
Dim wdApp As Object, wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("C:\Users\Javier\Desktop\[Nombre] Contrato.docx")
wdApp.Documents(wdDoc).Activate
'up until here the code works just fine
With wdApp.Documents(wdDoc).Selection.Find 'code doesn't go further than this because Run-time error '438': Object doesn't support this property or method'
.Text = "[NATIONALITY]"
.Replacement.Text = Nationality
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Any help will be appreciated!
Bookmarks