Solved

VB Excel: Read cell data, write it to a text file

Posted on 2000-04-05
2
470 Views
Last Modified: 2008-03-17
I need to read an excel data cell (row) and then print the data (array) to a text file.  Could someone provide a code snippet?
0
Comment
Question by:robjay
  • 2
2 Comments
 
LVL 22

Expert Comment

by:ture
Comment Utility
robjay,

This procedure reads rows 1-3, columns 1-5 from Sheet1 and writes to c:\test\test.txt

Sub ReadAndWrite()
  Dim ws As Worksheet
  Dim r As Long
  Dim c As Long
  Dim f As Integer
 
  Set ws = Sheets("Sheet1")
 
  f = FreeFile
  Open "c:\test\test.txt" For Output As f
 
  For r = 1 To 3
    For c = 1 To 5
      Print #f, ws.Cells(r, c),
    Next c
    Print #f,
  Next r
 
  Close f
End Sub

Ture Magnusson
Karlstad, Sweden
0
 
LVL 22

Accepted Solution

by:
ture earned 100 total points
Comment Utility
Just a friendly reminder...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now