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.
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?
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.
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"
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.
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.
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.
'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?
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
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?
Is it possible that when you press a command button, that the first thing it does is to execute the code assigned to another command button (IE in another sub).
FYI This is cross posted on the VB Forums at [URL].....
I know that you can use the below code to add buttons to 2 of Excel's menu systems,
Code:
Application.CommandBars("Worksheet Menu Bar").Controls.Add Application.CommandBars("Cell").Controls.Add
And this should add a command bar control of whatever type specified to either the Add-Ins tab of the ribbon or the right-click menu when clicking on a range of cells.
However, I would like to be able to add some command bar controls to the right-click menu when you click on a group of columns. Is this possible?
I just stuck on the basics. I want to add a new sheet through a macro and a button in the same. I am unable to make it dynamic. it is giving me an error:
I have a monthly log that I need to keep to track expenses and customers visited. The log is segmented into 12 parts corresponding with each month.
I need to be able to add multiple lines via an input box while maintaining the formulas and formatting of the 2 rows directly above the forms command button (because both lines are filled with a different color) but not the contents?
There will be 12 command buttons in all and the new rows should be added at the bottom (directly above where the button is)
I found this and it works to some extent.
Sub FromFormsCommandBar2() Dim Btn As Button with ActiveSheet Set Btn = .Buttons(application.caller) btn.topleftcell.entirerow.insert end with End Sub
I have built a Form which displays data from a spreadsheet. The user opens the form by clicking on a command button from the spreadsheet. The Form initially opens with the data from Row 4 of the spreadsheet (because this is the first row of the spreadsheet which contains the data for the form). The user can then sequentially access other rows in the spreadsheet by clicking on buttons in the Form which advance the extraction by one row.
I would like to add a command button to each row of the spreadsheet that would open up the Form and set the values in the Form to the same row which the command sits on.
Workbook performs perfectly 95% of the time but every now and again I have this issue where the formular do not calculate (it is set to automatic).
I have a workaround of doing a find and replace across all the worksheets of "=" replaced with "=" and this solves the issue.
The problem I am having is that some of the sheets are protected and some are not. The code I am using for the find and replace is as follows...
VB: Option Explicit Sub ChgInfo()
Dim WS As Worksheet Dim Search As String Dim Replacement As String
[Code] .....
I need to add to this code the unprotect command and then reprotect only the originally protected sheets?
I am sure these is a better way of doing this but im really short on time. This issue only occurs 5% of the time. the other 95% the formula all calculate fine!
I just need a way of doing the find and replace for = to = across all sheets in the workbook regardless of the sheet protection!!
I have a macro which I use to do all sorts of routine things on a spreadsheet for my employees. (you guys helped me with that too. thanks)
I would like to add a command button to this sheet to run series of code and I want to add this to the final step of a macro.
Question, is there a series of code, which would 1. create the command button on the active sheet, and 2. add the required code to the command button, and 3. embed that button and code onto the active sheet all at once.
?
I need to do this regularly so it is a currently manual process I am trying to replace.
Ex. of code I want placed:
Rows("1:1").Select Selection.Font.Bold = True
This is not the exact code which I will use, but it will help me to understand what I would have to do to make it work.
I have a user form with combo boxes. The user selects items from the combo box and when they click the command button the selection is written to the spreadsheet. Each time the button is clicked it adds an item to the sheet making a list of items. I am trying to assign a number to each item when the command button is clicked so I have numbered list. Here is my code so far:
Private Sub cmdbtnAdd_Click()
Dim RowCount As String
'Writes user inputs to Active Worksheet when Add Item Button is clicked.
RowCount = Worksheets("Sheet1").Range
("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet1").Range("A1")
.Offset(RowCount, 0).Value = ' This is where I have been trying to code in the numbering
CASH BK CASHIERS DATE CASH TOTAL DIFF SALES GBP AR GBP AR GBP
[code]....
above is the sheet template we use on a monthly basis. I would to like to use a command button which will run a macro creating a new sheet with the sheet name each month. The idea is to have a text box and a command button,enter the month in the text box and click the button. A sheet for the month to create at end.
I have a Excel 2007 spreadsheet of part numbers and quantities sold. In the spreadsheet we have similar part numbers, but my sumif command is adding these together. the parts are :
0124225031 R124225031
My column of part numbers is formatted as text
My formula is this =SUMIF(Sheet1!H:H,A16,Sheet1!Q:Q) where H is the part number and Q is the quanity
I tried adding a format command in the sumif command, but it returned a 0. =SUMIF(Sheet1!H:H,format(A16,"0"),Sheet1!Q:Q)
better formula and why is excel adding different part numbers together?
Is there any way to tell (from VBA) what GUI command is currently in progress or what the last command used was?
On a wish list perhaps: Application.LastCommand and/or Application.CurrentCommand
Let's say I'm in the "Sheet_Change" event and want to know what caused the change. Was the event triggered by "Delete", "Paste", "Keystrokes" ...
AutoCAD VBA has "Begin_Command (CommandName as String)" and "End_Command (CommandName as String)" events which I find very useful. Basically I'd like to emulate that to the greatest extent possible.
Application.Caller does not seem to work for the stated purpose. I've been searching for a workaround by means of reading the "Undo Stack". Numerous articles written by experts state that the undo stack is not accessible from VBA.
I've considered reading the text from the "Undo" button's caption but it just seems like such a hack ... not that this whole idea isn't a hack
How can I return name of a command button on click? I want to create some sort buttons on a sheet I will use regularly to speed things up. I thought if I could call each sort button by the column letter the button sits in I can use this in a single sub for all buttons
e.g the button sitting in column A is called "A". when i click the button, it returns it's name to a variable which I can then use to sort column A. I know I could create a seperate routine for each button but I was just trying to think of something neater.