Windows Scripting
  Home arrow Windows Scripting arrow Scripting Microsoft Word
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

Scripting Microsoft Word
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-10-06

    Table of Contents:
  • Scripting Microsoft Word
  • Creating and Opening Documents
  • Editing and Formatting Documents
  • Closing, Saving, and Exiting

  • 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


    Scripting Microsoft Word


    (Page 1 of 4 )

    Microsoft Word is a very powerful word processing application that is part of the Microsoft Office suite. It has become probably the single most widely used application of its type. But you already know this. What you may not know is that Microsoft Word was created with script automation in mind.

    The developers at Microsoft have included an OLE automation object for Word that allows you to control it both internally with macros and externally with WSH.  Today we’re going to explore this automation object and some of its uses.

    So some of you may be thinking, “Why should I even care?  I’m not going to automate typing a paper.”  And you’re probably right.  It would be far too tedious to automate typing a paper, but there are other possibilities.

    Word is excellent for creating reports.  You could create an automation that pulls information from a database, creates and formats a report, and then sends it off to a network printer.  Wouldn’t it be nice to have overnight sales orders waiting on the printer when you arrive at the office each morning?

    You already know that Microsoft Word can work very closely with an Access database for creating form letters.  Why not automate the creation of personalized form letters and envelopes for your entire mailing list?  And the possibilities go on.

    Getting started is pretty simple.  You first need to create an instance of the Word automation object.  This will differ slightly depending upon what language you use, but here’s what it looks like in VBScript.

    Set objWord = CreateObject("Word.Application")

    “Word.Application” is a version independent ProgId that will connect to the OLE object with the most recent version number.  So don’t worry if you have or have had multiple versions of Word installed; you’ll always be working with the most recent.

    This basically launches the Microsoft Word application in memory.  Let’s look at a couple of things we can do to control how the application opens.

    objWord.DisplayAlerts = False

    objWord.Visible = False

    DisplayAlerts is a Boolean property that, when set to False, suppresses file type warnings when opening older version files.  To avoid needing any outside user input, it’s a good idea to make sure that unnecessary message boxes are always suppressed.

    Visible is a hidden property that accepts a Boolean value that determines whether or not the Word application is displayed on screen or opened in the background.  Setting this value to True will make the application visible.  This is sometimes useful during script creation and testing.

    More Windows Scripting Articles
    More By Nilpo


       · In this article, we look at scripting the Microsoft's Word Automation Object for...
     

    WINDOWS SCRIPTING ARTICLES

    - 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
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





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