Windows Scripting
  Home arrow Windows Scripting arrow Advanced Word Object Scripting
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Advanced Word Object Scripting
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-10-20

    Table of Contents:
  • Advanced Word Object Scripting
  • Finding Text in a Word Document
  • Replacing Text in a Word Document
  • Using Word’s Spell Checker

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Advanced Word Object Scripting


    (Page 1 of 4 )

    In my last two articles I’ve demonstrated ways of using Microsoft Word through its OLE automation object. In this article, I’m going to show you a few more advanced scripting techniques that you can use. The first two are best used for data mining or mass-file editing while the last is a way of exploiting some of Word’s functionality for use in other environments.We’ll begin by taking a look at Word’s Find and Replace features. These features allow you to search a Word document for words or phrases and replace them.  You’ve more than likely used these features within the Word application so I’m not going to go into any more detail describing them. Instead, let’s learn how to script them!

    For now, we’ll focus on the Find feature. This can be useful for several different purposes. Perhaps you want to mine some data from a Word document. The Find feature would allow you to find that data quickly and efficiently. Or maybe you have a folder full of documents and you're looking for a quick way to identify which ones pertain to a specific topic. Whatever your purpose might be, scripting the Find feature could prove to be useful.

    Const wdFindContinue = 1

     

    strFindText = "Text to find"

     

    Set objWord = CreateObject("Word.Application")

    objWord.Visible = False

     

    Set objDoc = objWord.Documents.Open("mydoc.doc")

    As we’ve done before, we’ll begin our script by setting a few constants and variables, creating an instance of the Word application, and opening a document.  The strFindText variable should contain the text string that you wish to find in your Word document.

    Set objSelection = objWord.Selection

    Next we’ll want to create a selection containing the entire contents of the Word document. This allows us to search the entire document. Want to limit your search to a specific part of the document? That’s fine too. In that case, set your selection to only the parts of the document you wish to search. This could be a single page or even a single paragraph.

    More Windows Scripting Articles
    More By Nilpo


     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek