Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default 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 ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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 ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default 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 ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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 ***



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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 ***





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default 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 ***
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default 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 ***
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default 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 ***
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can excel run a batch file? Tom Excel Discussion (Misc queries) 2 June 1st 09 02:46 AM
Excel from Batch File Problem PcolaITGuy Excel Discussion (Misc queries) 2 January 10th 08 07:43 PM
Excel to Run a Batch File?!? carla New Users to Excel 3 January 20th 07 03:32 AM
Create a batch file from a number of Excel File Vinay[_2_] Excel Programming 0 September 8th 04 01:11 AM
Running a batch file from Excel VBA verizon Excel Programming 1 July 20th 03 09:27 AM


All times are GMT +1. The time now is 02:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"