EXPORT any record (row) to a formated txt file

M

msh

Hi
I want export every row to a seperated text file.
with MS-Word mail merge wizard I can read the xls file and create a formated
(with some content) file.
but I can't export it to seperated file.
1- In excel is any formula for export any row to the txt file (that have
some content).
2- How can this senario, with mail merge wizard in MS-Word.

---
My Excel file have this content:

MYNAME MYNUMBER
Name1 123
Name2 321
Name3 231
---
I want TXT file with this content:

[Credits]
name=MYNAME
[Global]
no=MYNUMBER
---
final txt file's

1.txt

[Credits]
name=Name1
[Global]
no=123

2.txt

[Credits]
name=Name2
[Global]
no=321

3.txt

[Credits]
name=Name3
[Global]
no=231
 
D

Dave Peterson

Change the path to what you need. It has to be an existing path, too.

Option Explicit
Sub testme01()

Dim iRow As Long

Close #1
With ActiveSheet
For iRow = 1 To .Cells(.Rows.Count, "A").End(xlUp).Row
Open "c:\my documents\excel\test\" & iRow & ".txt" For Output As #1
Print #1, "[Credits]"
Print #1, "Name = " & .Cells(iRow, "A").Value
Print #1, "[Global]"
Print #1, "no = " & .Cells(iRow, "B").Value
Close #1
Next iRow
End With

End Sub



Hi
I want export every row to a seperated text file.
with MS-Word mail merge wizard I can read the xls file and create a formated
(with some content) file.
but I can't export it to seperated file.
1- In excel is any formula for export any row to the txt file (that have
some content).
2- How can this senario, with mail merge wizard in MS-Word.

---
My Excel file have this content:

MYNAME MYNUMBER
Name1 123
Name2 321
Name3 231
---
I want TXT file with this content:

[Credits]
name=MYNAME
[Global]
no=MYNUMBER
---
final txt file's

1.txt

[Credits]
name=Name1
[Global]
no=123

2.txt

[Credits]
name=Name2
[Global]
no=321

3.txt

[Credits]
name=Name3
[Global]
no=231
 
M

MSH

This was exactly what I needed. It works beautifully. Many thanks.

MSH

Dave Peterson said:
Change the path to what you need. It has to be an existing path, too.

Option Explicit
Sub testme01()

Dim iRow As Long

Close #1
With ActiveSheet
For iRow = 1 To .Cells(.Rows.Count, "A").End(xlUp).Row
Open "c:\my documents\excel\test\" & iRow & ".txt" For Output
As #1
Print #1, "[Credits]"
Print #1, "Name = " & .Cells(iRow, "A").Value
Print #1, "[Global]"
Print #1, "no = " & .Cells(iRow, "B").Value
Close #1
Next iRow
End With

End Sub



Hi
I want export every row to a seperated text file.
with MS-Word mail merge wizard I can read the xls file and create a
formated
(with some content) file.
but I can't export it to seperated file.
1- In excel is any formula for export any row to the txt file (that have
some content).
2- How can this senario, with mail merge wizard in MS-Word.

---
My Excel file have this content:

MYNAME MYNUMBER
Name1 123
Name2 321
Name3 231
---
I want TXT file with this content:

[Credits]
name=MYNAME
[Global]
no=MYNUMBER
---
final txt file's

1.txt

[Credits]
name=Name1
[Global]
no=123

2.txt

[Credits]
name=Name2
[Global]
no=321

3.txt

[Credits]
name=Name3
[Global]
no=231
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top