|
Subject:
|
Reading excel and text files using VB6...
|
|
Posted By:
|
CJ35
|
Post Date:
|
8/5/2004 10:23:25 PM
|
Hello,
Can anyone please help with reading an excel file, as well as a text file and outputing that to a seperate text file using VB6?
|
|
Reply By:
|
Hari_Word
|
Reply Date:
|
8/11/2004 10:41:00 PM
|
I think for reading execl files you can use excel object library. And for reading you use Scripting.Filesystemobject.
Hari
|
|
Reply By:
|
Yehuda
|
Reply Date:
|
8/12/2004 9:14:50 AM
|
Depending on what you wish to read, you could use ADO to read excel. You could read text through the FileSystemObject or through the VB Open command. To write a text file you could use the FileSystemObject or the VB Open command.
|
|
Reply By:
|
almahdi
|
Reply Date:
|
9/17/2004 10:35:51 AM
|
Hi I have written a dll that connects to Excel and I want to send you the dll. Can you send me your email? my email address is almahdi@hotmail.com
Regards
|
|
Reply By:
|
Anantsharma
|
Reply Date:
|
9/27/2004 6:55:27 AM
|
HI,
Reading From Excel File :- ************************************************** Dim ExcelApp As Excel.Application Dim WS As Excel.Worksheet Dim i As Integer Dim stra As String
Set ExcelApp = CreateObject("excel.application") ExcelApp.Workbooks.Open (CommonDialog1.filename) Set WS = ExcelApp.ActiveWorkbook.Sheets("VendorSheet") ''Sheet For i = 1 to 10 stra="a"+cstr(i) Msgbox WS.Range(stra).value Next i
Above code will read 10 lines and column a of Excel sheet. Aa1,a2,a3......a10.
for other colums just create the range like "b1", "m10" etc. Hope u got the point. *******************************************************
Reading from text file:- *************************
'''Add reference to "MicroSoft Scripting runtime" to ur project then
Dim Fso as new FileSystemObject Dim FileToread As TextStream Dim CurrentLine as String
Set FileToread = fso.OpenTextFile("C:\a.txt", ForReading)
Do Whiile FileToread.AtEndOfStream = False CurrentLine=FileToread.ReadLine msgbox CurrentLine Loop
*******************************************
Writing to text file *********************** Dim FileToWrite as TextStream
Set FileToWrite = Fso.OpenTextFile("C:\mytxtfile", ForWriting, True)
FileToWrite.WriteLine "This is Line 1" FileToWrite.WriteLine "This is Line 2"
FileToWrite.Close **************
Hope this helps..Good luck..Happy programming
B. Anant
|
|
Reply By:
|
priya75
|
Reply Date:
|
10/8/2004 3:56:27 AM
|
Hi Anant,
I have to read the data from a table in MSWORD. Then I have to execute a macro which takes these inputs and generates a text file from it. I am a newbie to VB usage .Can you tell me in steps as to how do i make the VB script read the data from the MSWord Table.
An early response would be highly appreciated.
Regards Priya
quote: Originally posted by Anantsharma
HI,
Reading From Excel File :- ************************************************** Dim ExcelApp As Excel.Application Dim WS As Excel.Worksheet Dim i As Integer Dim stra As String
Set ExcelApp = CreateObject("excel.application") ExcelApp.Workbooks.Open (CommonDialog1.filename) Set WS = ExcelApp.ActiveWorkbook.Sheets("VendorSheet") ''Sheet For i = 1 to 10 stra="a"+cstr(i) Msgbox WS.Range(stra).value Next i
Above code will read 10 lines and column a of Excel sheet. Aa1,a2,a3......a10.
for other colums just create the range like "b1", "m10" etc. Hope u got the point. *******************************************************
Reading from text file:- *************************
'''Add reference to "MicroSoft Scripting runtime" to ur project then
Dim Fso as new FileSystemObject Dim FileToread As TextStream Dim CurrentLine as String
Set FileToread = fso.OpenTextFile("C:\a.txt", ForReading)
Do Whiile FileToread.AtEndOfStream = False CurrentLine=FileToread.ReadLine msgbox CurrentLine Loop
*******************************************
Writing to text file *********************** Dim FileToWrite as TextStream
Set FileToWrite = Fso.OpenTextFile("C:\mytxtfile", ForWriting, True)
FileToWrite.WriteLine "This is Line 1" FileToWrite.WriteLine "This is Line 2"
FileToWrite.Close **************
Hope this helps..Good luck..Happy programming
B. Anant
|