+ Reply to Thread
Results 1 to 8 of 8

Run a batch file from Excel

  1. #1
    Tempy
    Guest

    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. #2
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #3
    Tempy
    Guest

    Re: 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. #4
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #5
    Tom Ogilvy
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #6
    Tempy
    Guest

    Re: 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. #7
    Tempy
    Guest

    Re: 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. #8
    Tempy
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1