[Macro excel] How to create and export a sheet into a *.inp (or *.txt) file

M

MrKermit

Hi

I've got a little problem:
I would like to create with a macro a *.txt file in a specific folde
and copy the content of one the sheet on this *.txt file but I don'
know how to proceed.
In fact, I would be better for me to copy the content of this sheet i
a *.inp file (that is a quite weird extension), but a *.txt file woul
be good enough.

Thx for your hel
 
M

Mike Fogleman

Something like this:

Sub NewTextFile()
Sheets("Sheet1").Copy
ChDir "C:\" 'your folder path
ActiveWorkbook.SaveAs Filename:="C:\Book2.txt", FileFormat:=xlText, _
CreateBackup:=False
End Sub

Mike F
 
T

Tom Ogilvy

You might want to add

Sub NewTextFile()
Sheets("Sheet1").Copy
'ChDir "C:\" 'your folder path
ActiveWorkbook.SaveAs Filename:="C:\Book2.txt", _
FileFormat:=xlText, _
CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False
End Sub

You also don't need to chdir since the path is specified in the file name.
If you did need to Chdir, you should also Chdrive as well.
 

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