I am attempting to open the VB Editor in a word document and modify some
existing code. Example: In my code, I would like to change "ODBE.CalcTotal"
to "CalcTotal". I have to do this for about 100 word documents, so I did not
want to manually do it.
Following is the code that I have so far which works to the point of opening
the VB Editor. However, I need to write some code actually does the find and
replace.
Public Sub FixWordCode()
Dim oApp As Word.Application, MyDoc As Word.Document, MyDir As String, _
MyFile As String, MyRange
MyDir = CurrentProject.Path
Set oApp = New Word.Application
Set MyDoc = oApp.Documents.Open(MyDir & "\" & "TestOEDBTemplate")
oApp.Visible = True
MyDoc.Activate
MyDoc.Select
oApp.ShowVisualBasicEditor = True
***Everthing works fine up to here, but the next two lines do not work.***
Selection.Find.Execute FindText:="OEDB.", ReplaceWith:="", _
Replace:=wdReplaceAll
MyDoc.Save
MyDoc.Close
oApp.Quit
End Sub
From a security standpoint, maybe this is not possible. If anyone has any
input, I would appreciate it.
Thanks
Dave
Word Heretic - 09 Apr 2005 00:39 GMT
G'day "Umpty" <Umpty@discussions.microsoft.com>,
Not often a 4GL question arises. Use
ActiveDocument.VBProject.VBComponents(1).CodeModule.Find
and lose the VBE.
Steve Hudson - Word Heretic
steve from wordheretic.com (Email replies require payment)
Without prejudice
Umpty reckoned:
>I am attempting to open the VB Editor in a word document and modify some
>existing code. Example: In my code, I would like to change "ODBE.CalcTotal"
[quoted text clipped - 31 lines]
>Thanks
>Dave