Run Macro on add/drop in Visio - vba

Is there anyway to run a macro when you add or drop a shape from a container? Or is there a way to automatically run a small vba script every couple of seconds?

The Visio Shapesheet EventDrop cell lets you specify code to call when the shape is dropped on the page. It also works when duplicating the shape.
If it's a VBA macro then you can use CALLTHIS or RUNMACRO. CALLTHIS requires that the first argument in your VBA macro is a Visio.Shape object, where RUNMACRO does not.
I don't know of any way to run a macro every few seconds, at least not any way that works well.

Related

Vba Macro works but not starting in main()

Have created a Macro - multiple subs, functions and forms for Solidworks.
I'm sure the code is dubious but it works when I force it to start in main()
When I add a button in Solidworks to start the macro it defaults to a different sub, which appears to be alphabetical, I get a similar behaviour starting the macro from the editor.
It appears all the subs listed are the ones with no arguments passed in.
Could anyone please guide me on why this happens? I'm sure I could frig a way around by renaming the subs, but don't realy want to.
It appears I was to impatient, again!
When adding the macro button in Solidworks you are given the choice of choosing the sub to run ... as Method

Using Excel while macros are running

There are a half-dozen answers to this. "Open a second instance" "Have a pause" Etc. I'm not looking for that.
I'm looking for the user of the workbook to be able to manipulate the workbook while the macro is running. I've seen this working before, where the user could scroll around, change tabs, even add and remove data, all while the macro was running. Unfortunately, I couldn't get permission to look at the code (And committing CFAA violations ins't my cup of tea), so I have no idea how they did it.
How can you enable a user to edit the workbook as macros are running? For a specific example, I have Conway's Game of Life running. Users select cells to flip live/dead, then can run a macro to run the entire thing. I think it'd be nice for users to be able to change cells as the macro is running. (which is a second on select macro)
Thank you
Sorry just reread the question. I wouldn't expect the permutation to run for very long - not long enough to interrupt really.
But if it does, then the advice about using lots of DoEvents stands.
The other option is that you can use the OnTime event to have a "heartbeat"
VBA Macro On Timer style to run code every set number of seconds, i.e. 120 seconds
You can set the timer to say 3 seconds. Every time the OnTime event occurs you do one step of your permutation. In the three seconds in between they can edit.
Refactor your macro to use Events. In which case, you would have a series of event handlers (instead of one monolithic macro) to respond to various triggers. This is assuming that the macro is influenced by what the user is doing in the worksheet.
One way of (sort of) doing this is to use a Modeless Userform (UserForm.Show vbModeless)
The user form stays visible but the VBA stops running when the form is shown and the user can then interact with Excel. Then when the user clicks a button on the form the code behind the button starts running again.
So in reality the user is either interacting with Excel or interacting with the form ...

Excel vba: Auto run the routines

I have various routines in two different modules. Some clears the report, some populates it, fill the blank spaces with zeroes. I am currently running them using F5. But I want when the user opens the sheet, he gets all populated data without having to run that particular sub routine. Is it possible to run the routines in various modules automatically when the excel is opened?
This is pretty easy. Instead of putting code in the module, you will put it in ThisWorkbook and use the Workbook_Open event. You don't necessarily have to move your code. You can just call the existing macros.

Input values into an Input Box that was called by another Macro

I am writing a VBA macro that calls some macros from other Excel workbooks. These Macros are protected and I do not have the ability to see or modify their code. In one of the macros, an InputBox is called.
Is there a way to automatically trigger the OK button so that the InputBox does not load up (or pops up and then closes without prompting the user)? I can live with the default value for the input box to be used (though I'd also like to modify it if possible).
Please let me know if more information is needed - thanks in advance.
Have a look at example:
Sub MyMacro()
Call MacroInDifferentWorkbook
'here code to catch InputBox
End Sub
If you're trying to do that in that way, the answer is NO, you can't catch InputBox from MacroInDifferentWorkbook. It was well explained here:
Simulating Multithreading in VBA using Excel
Multithreaded VBA – An Approach To Processing Using VBScript

Passing parameter to VBA Macro

I am trying to run a macro when I double click on Visio shapes.
I want to pass the shape object to the VBA macro so that I could do something in the macro depending on the id of the Shape object.
Is it possible to pass the parameter to VBA macro. If yes, please let me know how?
Thanks.
You can put your macro as the EventDblClick event on the shapes you want to watch. To do this you would use the CallThis function (http://msdn.microsoft.com/en-us/library/aa212649(office.11).aspx) to have your macro called every time a shape is double-clicked.
This would require though, that you modify the shapesheet for every shape you want to watch. If you're providing the master(s) for the shapes you want to watch it shouldn't be a big deal, but otherwise you'd have to write code that will add the event to every shape you want to watch (though you could use the Document_ShapeAdded event on a document to add your event to the shapesheet whenever a shape is added)
When you click on an object, the Selection changes. You can use the Selection object in your macro to refer to the currently selected object.
I'm not sure if a macro can be run on double click, but my VBA experience does not come from Visio. As bit of googling turns up that this somehow seems to be possible. If you put it as a Button on a CommandBar, with a little more effort even in the context menu, you would be restricted to a Sub procedure without parameters in any case.