I want to paste text from Excel into a text file with the use of a macro...

  • Thread starter Thread starter VILLABILLA
  • Start date Start date
V

VILLABILLA

Hi,

I would like to know if it is possible to copy text from Excel into
text file with the use of a macro, I tried by recording a macro tha
copies data in Excel, opens a text or word file and pastes it in there
saving and closing the file.

I tried but it didn't work at all...

Is it possible to do this?

I did it with the use of the macro buttons, rec and stop because I'
not familair with VBE language... I have Office 2000

Any ideas?

Thanks a lot in advanc
 
Robby,

Instead of copying data to a textfile You may consider to sav
individual sheets to textfiles like the following sample shows:


Code
-------------------

Sub Export_CSV()
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim strPath As String
Set wbBook = ThisWorkbook

With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With

strPath = "c:\"

For Each wsSheet In wbBook.Worksheets
With wsSheet
.Select
.SaveAs strPath & .Name, xlCSV
End With
Next wsSheet

With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With

End Sub
 
You can write to a text file, or you can save the workbook as a text file. Try these two routines

Sub WriteToTextFile(
Dim rng As Rang
Set rng = Range("A1").CurrentRegio

Dim fso As New FileSystemObjec
Dim txt As Scripting.TextStrea
Set txt = fso.CreateTextFile("test.txt"

Dim cel As Rang
For Each cel In rn
If cel.Row = 2 The
' This will write everything in the second row to the file
txt.WriteLine cel.Valu
End I
Nex
txt.Clos
End Su
Sub ExportToTextFile(
ThisWorkbook.SaveAs "test.txt", xlTextWindow
End Su

-Brad Vontur
 

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

Back
Top