VBA Shell Command On A .BAT (batch) File
Jul 13, 2009
I was trying to run the shell command in VBA (excel2007) on a .BAT(batch) file. While running the macro, the DOS command prompt appears and goes away in a flash but the function of the .bat is not performed which makes me think that the shell command isnt functioning properly. I had this proper earlier also with a few Exe's.
the line of the macro that calls is (c is the path for the batch file) :
Call Shell(c, vbNormalFocus)
Could any of you help me with some suggestions regarding this problem.
Just to confirm, the batch file on itself works absolutely fine and it looks like it doesnt take more than 2 seconds to run it. It also does not wait for any input from the macro. it is an individual batch just included in the macro.
View 15 Replies
ADVERTISEMENT
Dec 9, 2011
I'm working on my first VBA project that requires 12 fields to be manually input of which one field is a file path. I need this path for multiple reasons, but the one reason I'm having a problem with is using the location of the path in conjunction with calling a bat file or executing a cmd prompt that is at that path.
Path Location, minus file name:
Code:
sheets("b. Fill Out Required Info").Select
Range("B18").Select
Actual Path found in B18:
C:UsersNickDesktopSubmission ToolTest Files
File attempting to execute:
CopyFileNames.bat
I can manually put all of this together and get what I want by using:
Code:
Shell "C:UsersNickDesktopSubmission ToolTest FilesCopyFileNames.bat", 1
The problem is, every time this will be used, a different path will be used, but the same batch file name will be used. So, rather than having to manually input the file path every time, is there a way to replace "C:UsersNickDesktopSubmission ToolTest Files" with the cell reference of the path listed above? I've tried different methods of this but I cannot seem to get it.
It would be even better if I could just use the cmd prompt found within the batch and run it directly from vba; the prompt I'm running is as follows:
Code:
cd C:UsersNickDesktopSubmission ToolTest Files dir /b/o |find ".xml">ListOfFileNames.txt
How can I put that cmd into VBA? I tried different versions of this with no success:
Code:
Shell "cmd.exe /c cd C:UsersNickDesktopSubmission ToolTest Files dir /b/o |find ".xml">ListOfFileNames.txt"
Notice that the path is the same as the path shown in B18 above. It would be great if that path would be dependent on the cell referenced above.
View 9 Replies
View Related
Dec 17, 2012
i have batch file that run from VBAexcel But the thing is i dont want to run batch file
i want everything on VBA . for example you use vba to cmd and then run this line of command
i have try but i just new to VBA and programing
how can i do it
here the code
this is from batch
Code:
@echo off
>summary.txt (
for %%F in (*chkpackage.log) do findstr /l %1 "%%F" nul||echo %%F:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A
)
and this is code in vba
Code:
FileSet = Sheet1.Range("C13")
txtFpath = Sheet1.Range("C7").Value
FilePath = txtFpath & "
es.bat"
[Code]...
i have to admit that i'm really not good in programing if you can add some explaination is a great thing for me to try to study
View 1 Replies
View Related
Apr 14, 2006
The VBA shell command is as follows:
programPath = "C:Program FilesInternet Exploreriexplore.exe" ' works
'programPath = "iexplore.exe" ' does not work
Shell programPath + " " + fileToLaunch, vbNormalFocus
but the drawback is that the invoked program (iexplore.exe, at least in my case) needs to have the FULL PATH to where the program exists = the "C:Program FilesInternet Explorer" which may or may not work on someone elses computer. This hardcoding will not work and is not transportable.
Is there a trick to find where the executing program lives? or launching it without the path?
View 9 Replies
View Related
Apr 19, 2014
I am playing around with the Forfiles command (being called from Excel via Shell)..
I can't for the life of me get it apply a second command (such as getting the file size of each file)..
For example:
VB:
Private Sub CommandButton1_Click()
Dim Z
Z = Split(CreateObject("wscript.shell").exec("cmd /c forfiles /P C:UsersapoDesktopTextFiles /S /M *.* /d
[Code]....
The end result being the filename and the filesize shown..
View 4 Replies
View Related
Jun 29, 2007
I have to run command prompt from with my VBA code , and run an application passing it 2 filenames and redirecting the output of the application to a third file. Also my VBA script should wait for the application to complete running before getting back to the next line of execution. HEre is what i have coded so far :
Sub Macro1()
Dim dosCmd As String
dosCmd = "purge.exe input1.txt input2.txt >> opFile.txt"
Call Shell("cmd.exe " & dosCmd, vbNormalFocus)
Now this code ends up just opening the command prompt and nothing else. It does not run purge.exe.
View 2 Replies
View Related
Aug 11, 2008
I have written a Shell command. It is very simple and designed to open another software. Here it is:
Dim X As StringX = Shell("C:Program FilesMicrosoft OfficeOFFICE11xlview.exe", vbNormal)
Is there a command that will close the open program? Something along the lines of
.....Ofice11xlview.CloseProgram", ...
But more importantly, is there a way to enter a second shell command after the first one that will have XLViewer to open a particular workbook after the viewer is open?
View 9 Replies
View Related
Nov 17, 2009
I'm very much in a bit of a pickle. I have updated my operating system from vista to windows 7 and a macro no longer works. The old code is
View 4 Replies
View Related
Nov 1, 2013
I'm trying to use a variable that hold a string in Shell string command. This shell is the command to take a snap picture over a given region and store the picture to a pre determined file name
***The code do compile***
The string variable is : StringAddress = "g: estsnapasnap1.jpg"
The following shell command will work
RetVal = Shell(("C:Program Files (x86)HyperSnap 7HprSnap7.exe " & " -hidden
-snap:x3602:y155:w1432:h830 -save:jpg g: estsnapasnap1.jpg"))
This one, with the string address variable, wont work
RetVal = Shell("C:Program Files (x86)HyperSnap 7HprSnap7.exe " & " -hidden
-snap:x3602:y155:w1432:h830 -save:jpg " & StringAddress)
View 1 Replies
View Related
Oct 15, 2008
I'm in the process of building a user form that required the user to brows for a file, the path of the file that they select is then displayed in the textbox next to the "browse" button in my form. I also have another button next to this which when selected will open the file that is displayed in the textbox previously mentioned.
I’ve been trying the shell command but with no success, I can get the user form to open adobe reader but whenever I try to include that file path for which to open the file I keep getting runtime errors,
Below are a couple of examples that I’ve tried (you'll prob be able to guess from the code that I’m very new to VB in excel).
For additional info the value in the textbox would be something like, "H:My DocumentsPDF Filesmyfile.pdf"
Dim GetFile As String
Shell "C:Program FilesAdobeReader 8.0ReaderAcroRd32.exe", vbNormalFocus
'this opens adobe reader but I'm trying to open a specific file
Shell "C:Program FilesAdobeReader 8.0ReaderAcroRd32.exe" & textbox9.value, vbNormalFocus
This produces the runtime error again
Dim GetFile As String
GetFile = TextBox9.Value
Shell "C:Program FilesAdobeReader 8.0ReaderAcroRd32.exe" & GetFile, vbNormalFocus
'this produced a runtime error - to be honest this was an attempt born out of frustration.
View 9 Replies
View Related
Oct 12, 2009
I want to run a Shell command to open lots of files.
I can get the basic command working, but I want to open a lot of different files and am seeing if there is a way to save time by having a variable input, rather than having 1000 different shell lines with IF statements.
View 8 Replies
View Related
Nov 3, 2009
I have written a For loop that uses a shell command to call a batch file that replaces text in some text file, Mytrail.txt. I then use that altered text file and use it to run a 3D modeling program Pro/Engineer by calling it through another shell command. I would like to add pause instructions to my routine after the shell commands. Below is a snippet of the code I am working with:
For i = 1 To N Step 1
Shell ("Reblacer.bat Mytrail.txt string_A string_B)
'Here I would like to add code that will pause the routine until the batch file 'operation is complete.
Shell "C:Program FilesproeWildfire 3.0inproe.exe Mytrail.txt", vbNormalFocus
'Here I would like to add another pause instruction until the above shell 'command is complete. Note that this shell command creates a new file in 'some directory whose name is actually string_A.prt. Could this be used to 'tell visual basic that it may recontinue executing the routine.
Next i
End Sub
How to add pauses to the routine above that prompt visual basic to continue executing the code only after the shell commands have completed their tasks?
View 2 Replies
View Related
Jul 27, 2014
I am using a shell command to communicate with a device under test and would like to open this shell once, change directory to a specific one and then send different text strings to it at various times during my test program. The code below works perfectly fine but opens and closed the shell each time it is used. I think it woud be quicker if I could reuse it until done and then exit out of it.
Here are 2 examples of a couple different strings I would like to pass into the cmdShell function at various times. I would like to send the first string, perform some measurements and then repeat with the 2nd string.
i.e. shellStr1 = ("cd .. & cd c:ezspi & testdm900 --widn 0x1020 --widv 0x1") then once the shell is open and the directory has been set send shellStr = ("testdm900 --widn 0x1020 --widv 0x5")
Is this possible using WShell Script or do I need another method?
Public Sub cmdShell(shellStr As String)
Dim Test As Double
Dim response As VbMsgBoxResult
Dim cmdObject As Object
Dim ReferenceTime As Double, ElapsedTime As Double
Set objShell = CreateObject("WScript.Shell")
[Code] .........
View 4 Replies
View Related
Oct 28, 2008
I know this is an excel forum but i'm struggling with something. i need to create a batch file that maps a network drive so far my searches have uncovered this
View 3 Replies
View Related
Apr 22, 2008
Is their a way of creating a batch file which will open an Excel workbook and run a single macro?
View 9 Replies
View Related
Oct 11, 2008
I realise this is not strictly an excel question but it forms part of my VBA code within excel
I have been writing a VBA program (with some fantastic help from you guys) part of which writes to a batch file to rename files stored in a given folder. Unfortunately this fails if the original files have spaces in the filenames. The batch file contains command lines such as: ...
View 6 Replies
View Related
Feb 24, 2009
I wanted to run a batch file which does something like,
Dir /b >Test.csv
Start Test.csv
And then runs an Excel macro once the workbook is open.
I looked into this and discovered that it’s not really that possible to run an excel macro through batch file but other options were to use ‘Workbook_Open’ etc.
I thought this might cause problems because Test.csv doesn’t contain a macro to auto open and because csv’s usually don’t like macros.
I do however have personal.xlsb which opens every time if that helps.
View 6 Replies
View Related
Oct 23, 2013
I have a workbook that contains worksheets. They are listed as follows:
Sheet 1ABCDEFG
In cells A1 - A49 I have text. What I would like to do is to have a macro that I can run that will basically copy and save new workbooks with sheets A - G copied over and have the new workbook saved with the file name that I have denoted in cells A1 - A49 on Sheet 1. Also, the macro would ask me where I want to save the new Workbooks.
For example, if this were Sheet 1, Column A then the cells below would be the saved name of the new workbooks and the new workbooks would have Sheets A - G in themRed
Blue
Purple
Black
White
Yellow
Orange
Green
Gray
Brown
One more piece of information, the file that is being copied and saved is large (~80MB). If there is a macro that would allow me to simply "save as' the workbook and the Saved Workbooks would be named using the data in Sheet 1, that would work as well in case copying, pasting, then saving may take more time
View 1 Replies
View Related
Mar 17, 2009
I have created a large process map workbook in excel that links to various areas within the document using command buttons.
However, one of the things I need users to be able to see s in a PowerPoint presentation.
All I need to do is create a command button that links to, and opens this .ppt file.
The .xsl and .ppt files will be distributed in a folder to other members of the team so I need the link to not be specific to my computer. Is it possible to avoid using the full path and just use a short path such as .../desktop/tools/process.xls so that as long as they store the folder on their own desktop the link works?
View 6 Replies
View Related
Mar 1, 2007
I have a wb with hyperlinks that open other .xls files stored on the LAN. When these files open, the Web Commandbar is displayed. I ran a macro to turn it off, then pasted the following code in the wb module but it doesn't work.
Private Sub Workbook_Open()
Application.CommandBars("Web").Visible = False
Application.Goto Reference:=Worksheets("Deviation Form").Range("A1"), _
Scroll:=True
End Sub
View 6 Replies
View Related
Jan 16, 2010
What is the code to open a URL or local html file with a command button?
View 4 Replies
View Related
Dec 17, 2012
Excel 2007 I have a button that will export the worksheet to pdf and save it as Acrobat requires. I have a network folder set up and it saves the file with the name that I have programed in the macro. I would like to have the file name set up to be what is in cell C3 then a space and the specific words.
For example, if C3 contains "123456" I want the file to be named "123456_Warranty Calculator"
I will end up using this in several worksheets which will have a different name as part of the file name (based on the worksheet name).
I would also like to have the last part of the file name be the worksheet name. ie, "Warranty Refund", "PDR Refune", etc.
I will have several users that will be using the workbook and possible saving at the same time and want each person to be able to find the one they saved instead of it being overwritten.
Code:
Excel 2007: I have a button that will export the worksheet to pdf and save it as Acrobat requires. I have a network folder set up and it saves the file with the name that I have programed in the macro. I would like to have the file name set up to be what is in cell C3 then a space and the specific words.
For example, if C3 contains "123456" I want the file to be named "123456_Warranty Calculator"
I will end up using this in several worksheets which will have a different name as part of the file name (based on the worksheet name).
I would also like to have the last part of the file name be the worksheet name. ie, "Warranty Refund", "PDR Refune", etc.
I will have several users that will be using the workbook and possible saving at the same time and want each person to be able to find the one they saved instead of it being overwritten.
View 2 Replies
View Related
Nov 18, 2009
I want to find the folder structure, but walking down. I have try this code
View 2 Replies
View Related
Jun 2, 2009
not sure why this is not working, it is from Access I know this is the wrong forum but figured I haven't got any answers from anywhere else and it seems like a simple fix
this command fails... i am guessing its to do with the file path having spaces but don't know how to get it to work, what to insert so it will work.
Call Shell("V:Program Files (x86)Microsoft OfficeOFFICE11WINWORD.EXE / L:Best Practice ManualFull Labour Hire Best Practice Manual.doc", 1)
View 9 Replies
View Related
Jul 3, 2006
I'm trying to run an application using a VB macro. The command line provided to me is "C:Program FilesWeb Scraper Plus+PkgExec.exe" -p "5A147DC7-0420-4321-9DEC-02B8D8111A78". This command line works fine from my Run menu. Now how do I write a Shell function to make this run from a VB macro?
View 4 Replies
View Related
Feb 25, 2014
I'm using excel 2010 and pdf creator to make a pdf (and open it automatically). It works with the following code:
[Code] .....
path and filename are previously defined objects.
I'm using pdfcreator because the code also has to be used with excel2003 on another pc. The problem is that I get an error (probably for trying to open the newly creating pdf-file).
Error 2417024894 (80070002) during execution. Method run of Object IWshSell 3 failed.
View 2 Replies
View Related
May 11, 2007
I know this is simple, but im having problems finding it in search. Im using the Shell method to open files, but how to open folders?
View 7 Replies
View Related
Mar 20, 2007
How can I make batch changes to graphs in the same excel workbook (but on different worksheets?)?
In particular, if I have a bunch of graphs, how can I make bulk changes to color, size, axes titles, etc.?
View 9 Replies
View Related
Aug 8, 2014
I have a VBA shell script that worked just fine on another computer, but now it won't run.
The code that won't execute is:
[Code] ........
View 12 Replies
View Related
Sep 15, 2009
Added pictures of the items to include on quotes (the pictures are in a column to the right of all the other details - (these pictures only exist in Excel)).
Our new quoting software tool needs a link to the filename - however, our pictures don't have logical filenames!
Is there a way we can do a batch save as of all these images so it ends up as 'part#'.jpg within folder X?
There are about 6,000 products and will be a bit of zombie work we don't really want to do!
View 14 Replies
View Related