+ Reply to Thread
Results 1 to 12 of 12

Using VBA to run BAT file but problem with folder name

  1. #1
    Registered User
    Join Date
    02-27-2014
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    6

    Using VBA to run BAT file but problem with folder name

    Hi I am new to this forum

    I have a batch file I am executing from excel vba. The batch file will not run if it is located in the following folder tree

    I:\Hvel\Data\Testing(ADM001)\GasCylinderInventory\BatchFiles

    If I remove the folder name (ADM001) then it works fine. I am unable to work out how to get this fixed.

    Any help is really appreciated.

    Thanks

    Peter

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Using VBA to run BAT file but problem with folder name

    without testing on my side....this might work....

    [code]
    FileName = "I:\Hvel\Data\Testing" & chr$(40) & "ADM001" & CHR$(40) & "\GasCylinderInventory\BatchFiles"
    [/code
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Registered User
    Join Date
    02-27-2014
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Using VBA to run BAT file but problem with folder name

    tried your suggestion and now "file not found" is displayed.

    I copy and pasted exactly as you suggested.

  4. #4
    Registered User
    Join Date
    02-27-2014
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Using VBA to run BAT file but problem with folder name

    here is the exact vba

    Sub Run_StockOutBat()

    Call Shell("I:\Hvel\Data\Testing" & Chr$(40) & "ADM001" & Chr$(40) & "\GasCylinderInventory\BatchFiles\StockOut.bat", vbReadOnly)

    End Sub

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Using VBA to run BAT file but problem with folder name

    Hello pfkelly,

    Batch files require using the old 8.3 DOS file names. You can get those from the newer long file names using the macro below.

    Add a new module to your VBA project and paste the macro code into it.

    Long Path Names to old 8.3 Format Names
    Please Login or Register  to view this content.
    Using the Macro
    Please Login or Register  to view this content.
    FolderName will hold the converted path that you can use.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Registered User
    Join Date
    02-27-2014
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Using VBA to run BAT file but problem with folder name

    Thanks for the reply,

    I entered the code and found the GetShortPathName is resulting in a compile error which is telling me the sub or function is not defined.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Using VBA to run BAT file but problem with folder name

    Hello pkelly,

    Are you running 64 bit Office?

  8. #8
    Registered User
    Join Date
    02-27-2014
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Using VBA to run BAT file but problem with folder name

    Hi Leith

    I am running 64 bit windows, 32 bit office

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Using VBA to run BAT file but problem with folder name

    Hello pkelly,

    I am running 64 bit Windows with 32 bit Office as well. Can you post a copy of your workbook? I would like to review the macro code.

  10. #10
    Registered User
    Join Date
    02-27-2014
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Using VBA to run BAT file but problem with folder name

    Hi Leith

    Here is my workbook.

    Thanks

    Peter
    Attached Files Attached Files

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Using VBA to run BAT file but problem with folder name

    Hello Peter,

    I have installed the code below in the attached workbook. Try it and let me know the results.

    Module1 Macro Code
    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,263

    Re: Using VBA to run BAT file but problem with folder name

    Hi Leith,

    You omitted the API declaration:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Lookup folder from cell text, then save excel file in this folder
    By dodgybob in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2014, 09:00 AM
  2. Get file names from folder problem!
    By mackypogi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2013, 05:01 AM
  3. Selecting Default Folder in Open File Dialogue Box Problem
    By PaulC in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-08-2010, 04:25 PM
  4. Replies: 6
    Last Post: 08-11-2006, 03:41 PM
  5. macro to move from file to file, folder to folder
    By davegb in forum Excel General
    Replies: 0
    Last Post: 01-21-2005, 04:06 PM

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