Yeah, it was my first try but it did not work, so I tried some other things like using activedocument.
Thx for testing the code. Now I know I got to find some solution.
Since the same code worked in word,
I have found some hacky work around, just watch and be amazed
Public Sub test()
Dim appWord As Word.Application
Dim docTemp As Word.Document
Dim rngManip As Word.Range
Set appWord = New Word.Application
appWord.Visible = True
'Set docTemp = PrepareTempDoc(appWord, strModelFile, strFieldMail, strTable)
Set docTemp = appWord.Documents.Open("C:\Documents and Settings\sroberge\Mes documents\test bd\result.doc")
DynamicCoder docTemp
CustomSearch appWord, "[-END-]"
'Now I can manipulate that F****** range :)
appWord.Selection.Range.Bold = True
End Sub
Public Sub CustomSearch(appWord As Word.Application, strToFind As String)
appWord.Run "Finder", strToFind
End Sub
Public Sub DynamicCoder(docWord As Word.Document)
Dim vbc As VBComponent
Set vbc = docWord.VBProject.VBComponents.Add(vbext_ct_StdModule)
vbc.name = "TempMod"
vbc.CodeModule.InsertLines 4, _
"Public Sub Finder(strToFind as String)" & Chr(13) & _
"Dim rngManip as Word.Range" & Chr(13) & _
"Set rngManip = ActiveDocument.Range" & Chr(13) & _
"rngManip.Find.Text =" & "strToFind" & Chr(13) & _
"rngManip.Find.Execute" & Chr(13) & _
"rngManip.Select" & Chr(13) & _
"End Sub"
End Sub