|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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! |
|
#2
|
||||
|
||||
|
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! |
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
||||
|
||||
|
Quote:
|
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > How to read contents of Ms Word file using vbscript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
![]() |
|