Solved! Go to Solution.
Solved by Hallex. Go to Solution.
Try this code
Option Explicit '' Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long '' Public Function RunCMD(ByVal FileName As String) As String RunCMD = ShellExecute(0, "open", FileName, "", "", 1) End Function '' Private Sub CommandButton1_Click() Dim fname As String fname = "C:\\Temp\\test.bat" RunCMD fname DoEvents MsgBox "| Done |" End Sub
~'J'~
hallex,
I tried it out but it still doesn't work.
As i Run the routine, click on the command button the cmd window pops and then the msgbox "DONE" but it is still not running the .bat file
I changed the path to the path where my .BAT is saved.
I have also independently checked the .bat file which defiantly works.
Do you have any other suggestions?
CJS
Try this project
Tested on A2009 only
Change bat file name in the code
~'J'~
Your coding works but i still can't get it to work on my bat routine,
However i think i have found the problem but can't find the solution,
i have tried it on 2 seperate routines.
I think the problem lies with the spaces. Here is my bat code:
@echo off setlocal enabledelayedexpansion title Drawing Lists color 0a cd "P:\027566\F08 - ITE\Sheet\CSK Transport\" dir "P:\027566\F08 - ITE\Sheet\CSK Transport\"*.dwg /b /s>CSKTransport.txt echo pause msg * List Created!
I am pretty sure the VBA part is correct as it is opening up this bat file (title "Drawing Lists" appears on DOS window)
any suggestions?
CJS
I used following bat file
@echo off setlocal enabledelayedexpansion title Drawing Lists color 0a cd "C:\Test\New Folder\" dir "C:\Test\New Folder\"*.dwg /b /s>CSKTransport.txt echo pause msg * List Created!
working good on my machine
I don't know how to fix your problem, sorry
Try search Google about blank spaces in the file name
or rename your folders
~'J'~
I have the same things often
Glad you solved it though
~'J'~
You should probably replace the .BAT code with VB for the best results:
Dim s as string, t as string, i as integer t = "P:\027566\F08 - ITE\Sheet\CSK Transport\" i = freefile() open t + "CSKTransport.txt" for output access write as #i s = Dir$(t + "*.dwg",vbArchive + vbHidden + vbNormal + vbReadOnly + vbSystem) Do While s <> "" print #i, t + s s = Dir$ Loop close #i
https://www.youtube.com/watch?v=1GAYtDkCG4A
watch how to execute a batch file using visual basic 6.0