+ Reply to Thread
Results 1 to 7 of 7

VBA to open .bat file

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    VBA to open .bat file

    Is there a way to use VBA code to open a .bat file?

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: VBA to open .bat file

    Something like:

    Sub Belfry()
        x = Shell("cmd.exe /c C:\TestFolder\sample.bat", 1)
    End Sub
    Gary's Student

  3. #3
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: VBA to open .bat file

    The file path leads onto the m drive. Should I change it to "cmd.exe/m" instead? This doesn't execute it either, but it is opening the command window permanently.

    Sub Belfry()
        x = Shell("cmd.exe /c M:\My Folder\Karen Postiglioni\JP\CSV Files\salesforce.com\Apex Data Loader 22.0\cliq_process\Update_Test_FNMA.bat", 1)
    End Sub

  4. #4
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: VBA to open .bat file

    The file path leads onto the m drive. Should I change it to "cmd.exe/m" instead? This doesn't execute it either, but it is opening the command window permanently.

    Sub Belfry()
        x = Shell("cmd.exe /c M:\My Folder\Karen Postiglioni\JP\CSV Files\salesforce.com\Apex Data Loader 22.0\cliq_process\Update_Test_FNMA.bat", 1)
    End Sub

  5. #5
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: VBA to open .bat file

    This is the error that I'm getting from the command line:

    '
    \\DTSDC02\Dignified\jsick\My Documents'
    CMD.EXE was started with the above path as the current directory.
    UNC paths are not supported.  Defaulting to Windows directory.
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

  6. #6
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: VBA to open .bat file

    It is quickly opening and closing the command window but it does not seem to be executing the bat file. When I double click it, it works fine. Any more ideas?

  7. #7
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: VBA to open .bat file

    Actually the code needed was much simpler. For some reason this works:

    shell "M\whatever\path\youwant\FILENAME.bat"

+ 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. A file iis found if I open Excel FIRST, but not if I open the file by double-clicking
    By Ed_Collins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2013, 01:52 AM
  2. [SOLVED] open variably named file, copy/paste data into consolidation file, open next file in list
    By sllawrence1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:49 PM
  3. VBA for excel 2003. Open file dialog box, open 2007 file xlsx, continue with code
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2011, 12:12 AM
  4. Replies: 1
    Last Post: 08-05-2006, 04:59 PM
  5. Open a file do a macro ( made) and open next succesive file
    By SVTman74 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-21-2006, 05:20 PM

Tags for this Thread

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