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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

    - 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...
    - Modifying XML Files in WSH
    - Reading XML Files in WSH
    - Visual Basic 2005 XML Programming Using XML ...
    - Creating an XML Document in WSH
    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT