VBA code for sending cells B6:J10 to text file.

  • Thread starter Thread starter lothario
  • Start date Start date
L

lothario

Hi,

Can you show me VBA code that copies contents of cells B6:J10 into a
plain text file?
By contents I mean the actual data and not the formulas, etc.

I cannot use "Save As" CSV because this data changes often so I need to
automate this process.


Thanks,
Luther
 
Sub MakeCSV()
Dim sh As Worksheet
Set sh = ActiveSheet
Workbooks.Add Template:=xlWBATWorksheet
sh.Range("B6:J10").Copy Destination:= _
ActiveWorkbook.Worksheets(1).Range("A1")
ActiveWorkbook.SaveAs Filename:="C:\MyCSV\" & _
Format(Now, "yymmdd_hh_mm") & ".csv", _
FileFormat:=xlCSV
ActiveWorkbook.Close SaveChanges:=False
End Sub
 
Luther,
The following will work:

sub test()
Range("B6:J10").select
ActiveWorkbook.SaveAs Filename:="C:\yourpath\test.txt", FileFormat:=xlText, _
CreateBackup:=False
end sub


Regards
Nigel
 
Back
Top