ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Save Worksheet at .txt (https://www.excelbanter.com/excel-programming/357866-save-worksheet-txt.html)

Sandeman[_22_]

Save Worksheet at .txt
 

Hello. I would like a macro to save a worksheet as a .csv file in
folder on my C drive. The worksheet will vary in size (rows an
columns). The sheet must use tabs as a delimiter.

Thanks for your help

--
Sandema
-----------------------------------------------------------------------
Sandeman's Profile: http://www.excelforum.com/member.php...fo&userid=3244
View this thread: http://www.excelforum.com/showthread.php?threadid=52922


Tom Ogilvy

Save Worksheet at .txt
 
A CSV file uses commas as delimiters

Activesheet.copy
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs "C:\Myfolder\Myfile.txt", xlText
Application.DisplayAlerts = True
Activeworkbook.Close SaveChanges:=False

--
Regards,
Tom Ogilvy

"Sandeman" wrote:


Hello. I would like a macro to save a worksheet as a .csv file in a
folder on my C drive. The worksheet will vary in size (rows and
columns). The sheet must use tabs as a delimiter.

Thanks for your help!


--
Sandeman
------------------------------------------------------------------------
Sandeman's Profile: http://www.excelforum.com/member.php...o&userid=32440
View this thread: http://www.excelforum.com/showthread...hreadid=529220



Sandeman[_23_]

Save Worksheet at .txt
 

Thanks Tom. Doesn't appear to work though as I get an error statin
some of the cells contain more than 255 characters, which stops th
macro in its tracks. Is there a workaround or another option

--
Sandema
-----------------------------------------------------------------------
Sandeman's Profile: http://www.excelforum.com/member.php...fo&userid=3244
View this thread: http://www.excelforum.com/showthread.php?threadid=52922


Dave Peterson

Save Worksheet at .txt
 
Maybe

Dim wks As Worksheet
Dim newWks As Worksheet

Set wks = ActiveSheet
wks.Copy
Set newWks = ActiveSheet
wks.Cells.Copy
newWks.Range("a1").PasteSpecial Paste:=xlPasteValues

Application.DisplayAlerts = False
newWks.Parent.SaveAs "C:\Myfile.txt", xlText
Application.DisplayAlerts = True
newWks.Parent.Close SaveChanges:=False



Sandeman wrote:

Thanks Tom. Doesn't appear to work though as I get an error stating
some of the cells contain more than 255 characters, which stops the
macro in its tracks. Is there a workaround or another option?

--
Sandeman
------------------------------------------------------------------------
Sandeman's Profile: http://www.excelforum.com/member.php...o&userid=32440
View this thread: http://www.excelforum.com/showthread...hreadid=529220


--

Dave Peterson

Sandeman[_24_]

Save Worksheet at .txt
 

That's the ticket. Thanks Dave

--
Sandema
-----------------------------------------------------------------------
Sandeman's Profile: http://www.excelforum.com/member.php...fo&userid=3244
View this thread: http://www.excelforum.com/showthread.php?threadid=52922



All times are GMT +1. The time now is 05:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com