How to shell to an exe and pass cell values from Excel worksheet - vba

Is this possible in Excel?
I have a workbook with multiple worksheets. I wrote some vba code in a code module to shell to an exe and pass it cell values as arguments.
What I want to be able to do is select a cell or row in any of my worksheets and then call my Shell Sub while passing the values from a couple cells to the Sub. A hot-key combination would be best.
The part I am having trouble with is calling a sub in a code module from a hot hey.
Can you help with this? Any sample code?
Much appreciated!

Found my answer! It was in a post from Leith Ross found here...
http://www.excelforum.com/excel-programming/590157-keyboard-shortcut-to-run-sub-module-in-vb.html
If your macro is a Sub then its easy to assign a shortcut key to your macro. While in Excel, type ALT+F8 to bring up the Macros List. Select the name of your macro by clicking it. At the bottom right corner of the dialog, click "Options..". You can then assign a shortcut key and add a description of the macro for other to see when it is selected in the Macro List.
That's exactly what I needed.

Related

vba , Autofill userform from another workbook cell selection

I have a workbook that used to be one with many sheets, I have now split the sheet to different workbooks.
The problem I now have is userform population from cell selection. When all the sheets were together. This code worked great.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not (UFMJobSelectForm.ActiveControl Is Nothing) Then
Call UpdateJobSelectForm
End If
End Sub
However now the Userform is in one workbook and this code is in another. I don't want to reference library as I need it to open and close so it can be accessed for other people to use.
Thanks for any help in advance.
Edit:
What i have is 4 different workbooks with jobs on and i want to select the job and the userform populates with job details.
The code I have detects the userform is open and then calls then populates the userform using updatejobselectform. Which worked when all the sheets were in the same workbook. however no longer works now i have separated them.
When i run this code now the sheets are in there own work books i get Error: runtime erroe 424 object required.
So what i am asking is dose anyone know how i can check a userform is loaded from in a different workbook and how i can get the useform to interact with cell selection from a different workbook.
thanks again.
This looks like a code that primafacie must fire when selection change event occurs, and call a function that must update the said form.
If the code and the said form are dependent, while splitting up should they not be together.
In case there are some other constraints that do not let you do so, and are not defined in the question do feel free to update the question / comment below.
Happy to help!

Excel thinks Combo Box is clicked when sheet is calculated in VBA

I have a number of private subs in Sheet code that refer to ComboBoxXX_Click. If I run another macro in the same Sheet that has SheetX.Calculate anywhere in the macro (referring to the sheet that contains the ComboBox) in the VB Editor using the step-into function, when it comes to execute the .calculate line it jumps to the ComboBoxXX_Click Macro. This makes me think that Excel is thinking that the ComboBox is clicked when the sheet is recalculated.
Try a different option instead of ComboBoxXX_Click
I suggest looking at the list of events that can be triggered on MSDN for that control.
try MouseDown
If you could add more information and blocks of code to help us help you. Also have you stepped through your code to find out at what point it is calling the ComboBoxXX_Click?
enter image description here
Here is an example of what I mean. Once the step into hits the Sheet4.Calculate on the first macro it skips to the second one (ComboBox25_Click) and if I step into the second one, once it reaches the Sheet4.Calculate line it also skips to a random ComboBoxXX_Click Macro.

How do I hotkey current sheet's VBA code?

I've had the issue of Worksheet_SelectionChange(ByVal Target As Range) triggering every time I click on something, which I don't want, as it means I have to wait every time I click in the actual sheet. I changed the code to Worksheet_Open, but that means I have to click the Run button whenever I want the code to run.
So I'm looking for a way of only running the current sheet's VBA code when I want to while I'm looking at the sheet (not while I'm in the VBA Editor). Ideally I'd be able to assign it to a hotkey using Application.OnKey, but I can't figure out how to refer to the sheet's code itself. The only solution I've found refers to an external macro, which isn't helpful, since I'm only wanting to use the code that's already in the sheet, as I'm using different macros for each sheet in the workbook.
Create a macro in a module for which you set the hot key, this macro will call the one you need:
CallByName ActiveSheet, ActiveSheet.Name & "Macro", VbMethod.
So you need to name the macros in the format of SheetNameMacro in each sheet.
More explanation: Trying to call a Sub with a String - VBA
Update
If your sheet names contains spaces then use this:
CallByName ActiveSheet, Replace(ActiveSheet.Name," ","_") & "Macro", VbMethod
and of course also replace spaces in your sheet (e.g. if your sheet called "list to delete" than macro name should be list_to_deleteMacro.

How do I run VBA code on ListObject Change?

I know that I can write the following code in a sheets' VBA-object to run code on a worksheet change.
Private Sub Worksheet_Change(ByVal Target As Range)
End Sub
Is there anything similar that I can write to run code whenever I filter a certain ListObject?
Only in some cases. Say we include a new column in the table that we fill with the value 1. Elsewhere we insert an
=SUBTOTAL()
formula to sum that column. As the filter is operated the number of visible rows will vary. The SUBTOTAL() function will re-calculate.
At this point a Calculate Event macro would catch the re-calculation!
Try this...
I added a ListBox Form Control to my Excel sheet..
Next, I assign a macro to this object by Right Clicking and choosing "Assign Macro". (you may need to be in "Design Mode" to make this happen -- check the Developer Ribbon)
By default - the Macro Name is populated with a change event macro name. Click "New" to create the macro.
Your macro is added to a Module. Hope this helps!

Running Sheet-Specific Macro from Other Sheet

I have a Excel book that has multiple sheets, subs, and macros. In order to make it a bit more user friendly, I'd like to create a dashboard sheet where the user has to just click buttons to run everything. This is possible easily with the subs, but how can I call a macro from one sheet to another? I can't seem to find any Excel documentation on this.
Put the subs in a Module as opposed to in each sheet object.
To Create a Module right click on the book name in the VBA editor and then choose Insert -> Module. Any sub will then be accessible to any sheet (or object) within that book.
If you have a Sub in a worksheet code module, you can call it from a regular code module (or any other module) like:
Sheet1.MySub
...where Sheet1 is the codename of the sheet containing the code you want to run.