SaveAs text file from VBA Getting Error

J

JeepNC

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
 
L

Lonnie M.

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.
 

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