• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3121
  • Last Modified:

How to Open a RTF file in VBScript and read text from it.

I am using VBScript in which I want to open a RTF file and read text from it.

Please provide a solution to this problem.

Regards,
Pranjal
0
pranjal_ds
Asked:
pranjal_ds
  • 3
2 Solutions
 
Krys_KCommented:
Hi There

This is a way to open an RTF file and read each line one by one, though you can read the whole file in one go if you like or even character by character (but thats not so common)

See if it helps

Regards
Krystian

P.S> change teh filename to suit you and see the comments as to where to do some things with each line we read.

	Call ReadFile
 
Sub ReadFile()
 
 ' Version 1.0
 ' Written by: Krystian Karia
 ' Dated: 22-12-2008
 
 
 	Dim fso, oFile
	Dim stroutput, arrComputers
	Dim strResults
	Dim tf
	
	Const ForReading = 1
	Const sFileLocation = "C:\Filename.rtf" ' <_______Change to suit
	
	
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set oFile = fso.OpenTextFile(sFileLocation, ForReading, False)
	
		If Err.Number <> 0 Then
			WScript.Echo "Error reading File " & sfileLocation
			Exit Sub
		End If
	
' Read the whole contents of the File
	Do While oFile.AtEndOfStream <> True
		strResults = oFile.ReadLine
 
' *******  Do some stuff here with the line we just read  *******
		WScript.Echo strResults
		
	Loop
	
' Close the file
	oFile.Close
	
' Release the object from memory
	Set oFile = Nothing
	
 
 
 End Sub 

Open in new window

0
 
pranjal_dsAuthor Commented:
Ok Thank you...!
0
 
pranjal_dsAuthor Commented:
Solution was ok.
0
 
pranjal_dsAuthor Commented:
Thank you
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now