ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SaveAs text file from VBA Getting Error (https://www.excelbanter.com/excel-programming/321905-saveas-text-file-vba-getting-error.html)

JeepNC

SaveAs text file from VBA Getting Error
 
I have the following code trying to save an excel sheet as a text file I get
the following error message. Any suggestions?

Thanks,

Dim xlx As Object, xlw As Object, xls As Object, xlc As Object

Set xlx = CreateObject("excel.application")
xlx.Visible = True
Set xlw = xlx.workbooks.Open("C:\book1.xls")
Set xls = xlw.worksheets("sheet1")
xls.Columns("K:K").NumberFormat = "0"
'ActiveWorkbook.SaveAs Filename:="C:\Book1.txt", _
' FileFormat:=xlText, CreateBackup:=False
xlw.SaveAs Filename:="C:\Book1.txt", _
FileFormat:=xlText, CreateBackup:=False

Here's the error
SaveAs method of workbook class failed

Lonnie M.

SaveAs text file from VBA Getting Error
 
Hi, I am not sure that you used a valid xlfileformat. in the VBA editor
pres 'F2' and search 'xlfileformat'. This will give you the various
xlfileformat that are available.

HTH--Lonnie M.



All times are GMT +1. The time now is 11:55 PM.

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