Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel VBA - Exporting values to a txt file

Hi everyone!!

i wanna do a macro for an excel file, and i want it to do the
following:

1 - Get the values one by one from a column
2 - Put the values in a txt file.

Example:

Excel file:

A B
1 hello
2 world
3 welcome
4 everybody
5
6
7


Text file:

hello
world
welcome
everybody

It seems to me that this must be very very easy to do, but i am very
very new in the Visual Basic world, and i dont have any idea of the
names of the methods.

If anyone can help me... thanks

Schumacker
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Excel VBA - Exporting values to a txt file

Hi Schumacker

See if any of this is of use:

Sub Export2Textfile()
Dim Textfile As Variant
Dim LastRow As Long
Dim XportArea As Range
Dim Cel As Range
Dim iFnum As Integer
'Select a textfile to save to
Textfile = Application.GetSaveAsFilename( _
InitialFilename:="text.txt", _
FileFilter:="Text files, *.txt)", _
Title:="Save textfile as:")
If Textfile = False Then Exit Sub
On Error Resume Next
'Select the cells to export:
Set XportArea = Application.InputBox( _
"Select the cells to export:", _
"Use your mouse:", Selection.Address, Type:=8)
If XportArea Is Nothing Then Exit Sub
'open / create the textfile
iFnum = FreeFile
Open CStr(Textfile) For Output As iFnum
'loop cells
For Each Cel In XportArea
'write to textfile
Print #iFnum, Cel.Text
Next
Close #iFnum
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"schumacker" skrev i melding
om...
Hi everyone!!

i wanna do a macro for an excel file, and i want it to do the
following:

1 - Get the values one by one from a column
2 - Put the values in a txt file.

Example:

Excel file:

A B
1 hello
2 world
3 welcome
4 everybody
5
6
7


Text file:

hello
world
welcome
everybody

It seems to me that this must be very very easy to do, but i am very
very new in the Visual Basic world, and i dont have any idea of the
names of the methods.

If anyone can help me... thanks

Schumacker



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Excel VBA - Exporting values to a txt file

Hello Schumaker

Sub EcrireFichierTexte()
Dim Montexte As String
'adapt path and textfile name
Open "D:\Mes Documents\TestEcriture.txt" For Output As #1
'adpat column
For i = 1 To Range("A65536").End(xlUp).Row
Montexte = Cells(i, 1)
Print #1, Montexte
Next i
Close #1
End Sub

HTH
Regards
Pascal

"schumacker" a écrit dans le message de
om...
Hi everyone!!

i wanna do a macro for an excel file, and i want it to do the
following:

1 - Get the values one by one from a column
2 - Put the values in a txt file.

Example:

Excel file:

A B
1 hello
2 world
3 welcome
4 everybody
5
6
7


Text file:

hello
world
welcome
everybody

It seems to me that this must be very very easy to do, but i am very
very new in the Visual Basic world, and i dont have any idea of the
names of the methods.

If anyone can help me... thanks

Schumacker



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting the values to excel error Karthik Excel Discussion (Misc queries) 1 May 31st 10 01:21 PM
Exporting MS Project Values into Excel Paul Peterson - Velox Consulting, LLC Excel Worksheet Functions 2 October 13th 08 06:55 PM
Exporting excel to text file Exceluser Excel Discussion (Misc queries) 1 June 22nd 05 11:26 PM
Exporting excel to text file Exceluser Excel Discussion (Misc queries) 1 June 22nd 05 05:33 AM
Exporting from Excel to a text file Josh Brien Excel Discussion (Misc queries) 3 May 20th 05 09:54 PM


All times are GMT +1. The time now is 08:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"