I have an Excel spreadsheet what holds data is cells on various tabls (worksheets). I have built some VB 6 code in a macro to propagate through the sheets and build comma deliminted lists in a text file out of the data is the sheets. I can create the files, but I cannot seem to find a good way to get data into those files.
Here is some of the code:
Some of the code listed above isn't being used because I am testing on a local machine.
I want to have the text file to be something like this:
"<SheetName>", "1"
"<Value>","<Value>","<Value>"
All dependant on what the sheet name and values are.
Any help is greatly appreciated. Thanks.
Here is some of the code:
Code:
Function CreateFile(FileName AS Object) As Object
Dim File As Object
Dim TxtStream
Dim Response
Dim Existing File As Object
FileName = "c:\" & FileName
Set File = CreateObject("Scripting.FileSystemObject", "")
If (File.FileExists(FileName)) Then
Response = MsgBox("The file exists, please remove.")
End
Else
Set TxtStream = File.CreateTextFile(FileName)
Set CreateFile = TxtStream
End If
End Function
Sub Process()
Dim AgentNumber, SheetName, Sheet, Path, Server, FileName As String
Dim File As Object
Dim Response
Dim RowNum, SheetSelectNum As Integer
Dim RowSelect, RangeValue As String
Dim Flag As Integer
Sheets("Instructions").Activate
AgentNumber = Range("A1").Value
Server = Range("A2").Value
Path = Range("A3").Value
Flag = 1
SheetSelectNum = 1
RowNum = 3
Do While (Flag)
Sheets("Instructions").Activate
SheetName = AgentNumber & "_" & Range("B" & SheetSelectNum).Value
Sheets(SheetName).Activate
FileName = SheetName & ".txt"
Set File = CreateFile(FileName)
//Here is where I want to write the data from the sheet to the text file
Some of the code listed above isn't being used because I am testing on a local machine.
I want to have the text file to be something like this:
"<SheetName>", "1"
"<Value>","<Value>","<Value>"
All dependant on what the sheet name and values are.
Any help is greatly appreciated. Thanks.
