Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2005

Tip: Looking for answers? Try searching our database.

Programmatically Modify Code in Word Document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Umpty - 06 Apr 2005 19:47 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.