Windows Scripting
  Home arrow Windows Scripting arrow Reading and Printing Word Documents in WSH
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

Reading and Printing Word Documents in WSH
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-10-13

    Table of Contents:
  • Reading and Printing Word Documents in WSH
  • Printing Word Documents
  • Advanced Printing Options
  • Page Setup options
  • Printing Page Ranges and more

  • 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


    Reading and Printing Word Documents in WSH


    (Page 1 of 5 )

    In my last article, I showed you how to connect to Microsoft Word’s OLE automation object to open and create documents. You also learned how to edit and save them. In today’s article, I’m going to take things a bit further and show you some scripting techniques that can be used to perform some more advanced functions.

    We’ll begin with one of the most popular requests I receive.  I’m constantly being asked how to read text from a Word document.  Well, you’re in luck because I’m going to show you how—and it’s actually pretty simple.

    To get started, you’ll either need to open a document or create a new one and fill it with some text.  You learned how to do both in my last article so I won’t go into too much detail.

    Const wdDoNotSaveChanges = 0

     

    strDocument = "C:mydoc.docx"

     

    Set objWord = CreateObject("Word.Application")

    objWord.Visible = False

    objWord.DisplayAlerts = False

    objWord.Documents.Open strDocument,, True

    Set objDoc = objWord.ActiveDocument

    What I’ve done here is created an instance of the Word automation object, set some basic properties, and opened an existing Word document.  In this example, I’ve opened the document as read-only to prevent accidentally saving any changes.

    Set objRange = objDoc.Content

    strContents = objWord.CleanString(objRange.Text)

    Next, I set a range that includes the entire contents of the document using the Document object’s Content property.  That Range object has a Text property that returns a text string containing the text of that range.  I’ve gone a little further by using the Word object’s CleanString function as well.  This function will remove any Word-specific formatting from the string.

    objWord.Quit wdDoNotSaveChanges

     

    MsgBox strContents

    I finish up by closing the Word application and displaying the contents in a message box.  Of course, you could use this text string in any way you like.

    More Windows Scripting Articles
    More By Nilpo


       · In the second installment of this series, I show readers some of the more advanced...
     

    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 2 hosted by Hostway
    Stay green...Green IT