Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2004, 10:23 PM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reading excel and text files using VB6...

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?

 
Old August 11th, 2004, 10:41 PM
Authorized User
 
Join Date: Jul 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think for reading execl files you can use excel object library.
And for reading you use Scripting.Filesystemobject.

Hari

 
Old August 12th, 2004, 09:14 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 205
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old September 17th, 2004, 10:35 AM
Registered User
 
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 [email protected]

Regards

 
Old September 27th, 2004, 06:55 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

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
 
Old October 8th, 2004, 03:56 AM
Registered User
 
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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:
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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading text files senthilreddy ASP.NET 2.0 Basics 1 May 22nd, 2007 08:32 AM
Reading from Excel Files interrupt Javascript How-To 8 September 28th, 2006 09:31 AM
Reading excel files dotnetprogrammer VS.NET 2002/2003 1 June 29th, 2005 07:01 AM
Regarding " reading text files" spraveens Classic ASP Basics 1 October 14th, 2003 07:46 AM
Reading/Creating/Writing Excel FIles p_nut33 C# 1 September 2nd, 2003 12:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.