View Full Version : Solved: Export data to .txt file
cactus
09-17-2007, 04:51 PM
Hi
I`m using a uerform to do a survey and every time the user submit a register, I need to tore it in the same .txt (each user has their own .txt file).
In other words, diferent regiters submitted in diferent times, sotored in a same .txt file.
Thanks in advance
mvidas
09-18-2007, 06:16 AM
Hi Cactus,
You can add-on to an existing text file by appending to it; this is a very simple example (since I obviously don't know your setup, either in the file or in the form) but should give you an idea of what to do: Dim vFF As Long, vFile As Long
vFile = "C:\your output.txt"
vFF = FreeFile
Open vFile For Append As #vFF
Print #vFF, TextBox1.Text & "," & TextBox2.Text & "," & TextBox3.Text
Close #vFF
cactus
09-19-2007, 04:38 AM
Beautiful!!!
Simple and efficient.
Thanks.-
andysuth
11-21-2007, 03:42 AM
I've been hiding, but needed to use an "append" for a text file.
I think there's a typo in that routine (correct me if I'm wrong, but I couldn't get it going) Shouldn't vFile as Long be vFile as string?
I couldn't get it going whilst passing the file location to vFile as a "Long", but when it was changed to "String" it seemed happier.
This is the full sub that I am using, which does a few extra things on top, such as saving the active spreadsheet as a text file.
There are a few global variables like "Path String" etc in the code, relevent bit is from "MSGBOX" (my rough and ready reak points) downwards.
-AS
Sub textmaker(code As String, verint As Integer)
Dim vFF As Long, vFile As String, xls As String, txt As String
' copies the hidden sheet to new file name.
xls = pathstring & "autoframe.xls"
txt = pathstring & verint & filestring & ".txt"
Sheets(code).Select
Range("B3").Select
ActiveCell.Value = verint & code
Sheets(code).SaveAs Filename:=txt, FileFormat:=xlTextPrinter, CreateBackup:=False
ActiveSheet.Name = code
If Dir(xls) <> "" Then
Kill (xls)
End If
ActiveWorkbook.SaveAs Filename:=xls, FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
'MsgBox ("go for it")
vFile = pathstring & "historical.txt"
Range("B4").Select
vFF = FreeFile
Open vFile For Append As #vFF
Print #vFF, verint & "," & Now() & "," & ActiveCell.Value & "," & code
Close #vFF
'
'
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.