Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old August 7th, 2006, 09:26 PM
andrew_bonn andrew_bonn is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 26 andrew_bonn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 56 sec
Reputation Power: 0
Question How to read contents of Ms Word file using vbscript

Hi!Can anyone help me on how to create a vbscript that will read the contents of an MS Word file. I will need to read the contents of an ms word file line by line so that i can perform some string functions. I will need this to automate certain task. Please help.Here is my code:

Code:
dim fso,ostream,stxt
set fso=CreateObject("Scripting.FileSystemObject")

if fso.FileExists("c:\test2\test.doc") then
    set ostream = fso.Opentextfile("c:\test2\doc.doc",1)
    Do until ostream.AtEndofStream
	stxt = ostream.Readline
	Msgbox stxt
    Loop
End if


For testing purposes I tried to display the line by line contents of the Ms word file into a message box. Unfortunately, it just displays garbled characters. What's the right way to do this?I'll appreciate any help from u guys!

Reply With Quote
  #2  
Old November 21st, 2006, 08:37 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 675 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Days 18 h 35 m 6 sec
Reputation Power: 308
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
The problem here is that Word files are not plain text files. You need to be able to handle the Word formatting. In order to do that, your best bet is to use Microsoft Word itself.

You can create an instance of Microsoft Word by instantiating it's ActiveX control object:
Code:
Set objWord = CreateObject("Word.Application")


Now you can open a file by using the Documents.Open() method which returns a file object:
Code:
Set objDoc = objWord.Documents.Open("C:\myfolder\mydoc.doc")


At this point, you can treat your object as a standard text file and use any of VBScript's Read methods. Don't forget that you will still contain special characters such as LF's.
__________________
Click the image if at any point you don't like my decision.

Scripting problems? Windows questions? Ask the Windows Guru!


Reply With Quote
  #3  
Old April 4th, 2008, 05:46 PM
benji_crispin benji_crispin is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 1 benji_crispin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 59 sec
Reputation Power: 0
Opening an Excel file

Hi, I have been having a similar problem. I do not know how to open an Excel file. I have experimented with the code you have given , but i have not had sucsess. Please could you reply if you fell that you can help. Thanks.

Reply With Quote
  #4  
Old April 5th, 2008, 03:33 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 675 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Days 18 h 35 m 6 sec
Reputation Power: 308
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Quote:
Originally Posted by benji_crispin
Hi, I have been having a similar problem. I do not know how to open an Excel file. I have experimented with the code you have given , but i have not had sucsess. Please could you reply if you fell that you can help. Thanks.
Opening an Excel file is done almost identically except that you will be using the Excel object.
vb Code:
Original - vb Code
  1. Set objExcel = CreateObject("Excel.Application")
  2. Set objWorkbook = objExcel.Workbooks.Open("C:\myfolder\myworkbook.xls")
Comments on this post
micky agrees!

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > How to read contents of Ms Word file using vbscript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway