ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run a batch file from Excel (https://www.excelbanter.com/excel-programming/329617-run-batch-file-excel.html)

Tempy

Run a batch file from Excel
 
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

*** Sent via Developersdex http://www.developersdex.com ***

Bob Phillips[_7_]

Run a batch file from Excel
 
You don't need DOS, you can do it from VBA

Name oldpathname As newpathname

--
HTH

Bob Phillips

"Tempy" wrote in message
...
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

*** Sent via Developersdex http://www.developersdex.com ***




Tempy

Run a batch file from Excel
 
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

*** Sent via Developersdex http://www.developersdex.com ***

Bob Phillips[_7_]

Run a batch file from Excel
 
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

--
HTH

Bob Phillips

"Tempy" wrote in message
...
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

*** Sent via Developersdex http://www.developersdex.com ***




Tom Ogilvy

Run a batch file from Excel
 
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

--
Regards,
Tom Ogilvy




"Tempy" wrote in message
...
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

*** Sent via Developersdex http://www.developersdex.com ***




Tempy

Run a batch file from Excel
 
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

*** Sent via Developersdex http://www.developersdex.com ***

Tempy

Run a batch file from Excel
 
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

*** Sent via Developersdex http://www.developersdex.com ***

Tempy

Run a batch file from Excel
 
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

*** Sent via Developersdex http://www.developersdex.com ***


All times are GMT +1. The time now is 01:33 AM.

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