Run a batch file from Excel

T

Tempy

Good morning,

Is it possible to run a Dos batch file with code from Excel ?

I save a file as a ".PRN" with excel and must then change it to ".DAT"
and want to do this with my code & not have to go to the file right
click and then "change name" and put in ".DAT".
It needs to be ".DAT" so that it can be used in SAP.

Thanks in advance.

Tempy
 
T

Tempy

Hello Bob,

I have tried using the code below but it does not work ?
Could you please heeeelp ?
The code runs, but does not change the ".PRN to ".DAT"

ChDir "\\zapad01\sapinter"
ActiveWorkbook.SaveAs Filename:="\\zapad01\sapinter\GPS" & res &
".PRN", _
FileFormat:=xlTextPrinter, CreateBackup:=False
ActiveWindow.Close
OldName = "\\zapad01\sapinter\GPS" & res & ".PRN": NewName = _
"\\zapad01\sapinter\GPS" & res & ".DAT"


Tempy
 
B

Bob Phillips

Hi Tempy,

Try this

ChDir "\\zapad01\sapinter"
ActiveWorkbook.SaveAs Filename:="\\zapad01\sapinter\GPS" & res & ".PRN",
_
FileFormat:=xlTextPrinter, CreateBackup:=False
ActiveWindow.Close
OldName = Activeworkbook.path & "\"& res & ".PRN"
NewName = Activeworkbook.path & "\"& res & ".DAT"
Name Oldname As Newname
 
T

Tom Ogilvy

Where is the line of code that does

ActiveWorkbook.SaveAs Filename:="\\zapad01\sapinter\GPS" _
& res & ".PRN", _
FileFormat:=xlTextPrinter, CreateBackup:=False
ActiveWindow.Close
OldName = "\\zapad01\sapinter\GPS" & res & ".PRN"
NewName = "\\zapad01\sapinter\GPS" & res & ".DAT"
name Oldname to NewName

anyway, just naming it DAT from the start worked for me:


ActiveWorkbook.SaveAs Filename:="\\zapad01\sapinter\GPS" _
& res & ".DAT", _
FileFormat:=xlTextPrinter, CreateBackup:=False
 
T

Tempy

Hi Bob,
Thanks for the reply, i tried it and i get an error when it gets to>
Name Oldname As Newname - the error is File not found Runtime error 53


ChDir "\\zapad01\sapinter"
ActiveWorkbook.SaveAs Filename:="\\zapad01\sapinter\GPS" & res &
".PRN", _
FileFormat:=xlTextPrinter

Oldname = ActiveWorkbook.Path & "\\zapad01\sapinter\GPS" & res &
".PRN"
Newname = ActiveWorkbook.Path & "\\zapad01\sapinter\GPS" & res &
".DAT"
Name Oldname As Newname



Tempy
 
T

Tempy

Hi Tom,
I have also succesfully saved it as a ".DAT" file, but when i opened it,
it is just full of Asxi code ??

Tempy
 
T

Tempy

Hi Again Tom,

I have just changed the code to yours and it works great.

thank you both for your perseverance and great help.

Thank you

Tempy
 

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