View Full Version : Solved: BAT file
mdmackillop
03-11-2011, 07:05 AM
I'm trying to run a simple bat file using Shell
Call Shell("C:\pdf2txt\YourPage.bat", 1)
The file contains one line: pdftotext.exe -layout YourPage.pdf
The file runs properly if I double click it in Explorer, but from code, the Dos window flashes on the screen but no output is created.
Any ideas?
mdmackillop
03-11-2011, 07:26 AM
Issue resolved. My drive was set to Z: by an earlier code line. I had the line
ChDir ("C:\pdf2txt\")
but this did not change the drive. Resetting the drive as below worked.
ChDrive "c:\"
ChDir ("C:\pdf2txt\")
Call Shell("YourPage.bat", 1)
Hi Malcom,
Just because I was already banging my poor noggin on the desk, but think I finally got it... In case you did not want to change drives etc...
Sub exa()
Dim FPath$
FPath = CreateObject("Scripting.FileSystemObject").GetFolder(ThisWorkbook.Path).ShortPath
Call Shell(Environ("COMSPEC") & " /c" & "start /D" & FPath & " RunSort.bat", vbNormalFocus)
End Sub
Have a great weekend :-)
Mark
Kenneth Hobs
03-11-2011, 09:44 AM
You need the code to shell and wait. See Chip's example code: www.cpearson.com/Excel/ShellAndWait.aspx
mdmackillop
03-12-2011, 02:02 PM
Thanks both. I'll check it at work on Monday
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.