Passing parameter to VBA Macro - vba

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.

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

BERT delay in shape with graphic

I am having a problem moving a shape created by BERT in my VBA code. If I run the VBA macro that calls Bert to create the chart, and then submit in a second call for the code to move the shape, it works. If I try to combine the code it does not work. I think it's possible the shape does not yet exist when I combine calls. I can also make it work if I call the move code from a worksheet event such as "SelectionChange." However, this make the application look awkward.
https://github.com/sdllc/Basic-Excel-R-Toolkit/issues/116
So I'm not sure why this happens, but it has something to do with the interaction between VBA, COM and R. In any event you can work around it by adding a shape with the name first (if it doesn't already exist).

Run Macro on add/drop in Visio

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.

handle Powerpoint shape click event in c# code

I want to handle a powerpoint shape's click event in slide show mode.
I want to write event handler in a C# vsto addin.
Please help me I am stuck in this as in google search I am not able to find any answer to this.
In normal view, you could respond to the Selection Changed event to determine whether a particular shape had been clicked, but you can't select anything in slide show view.
But you can assign an action setting to a shape, make it a Run Macro action and have it call a bit of VBA code within the presentation, for example:
Sub AndThenHeClickedMe(oSh as Shape)
MsgBox "You clicked " & oSh.Name
End Sub
Your VBA code could possibly call a DLL that you provide as well, so you don't need to write all of the following code in VBA if you don't wish to.

Excel: Fixed Button Position

Needing some help attaching an Excel/VBA button on an Excel sheet. I need it to stay in the same position on the screen regardless of how I scroll or zoom. Preferably, I need this on the bottom left or right of the screen.
I have tried adding a button. Then, I right clicked on the button. Clicked on Format Controls -> Properties -> selected Don't Move or Size With Cells. Am I missing something that's making this not work?
Thanks!
I know this post is old, but here's to anyone it could be useful. The VisibleRange property of ActiveWindow can solve this problem. Use something like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ActiveSheet.OLEObjects("MY_BUTTON'S_NAME")
.Top = ActiveWindow.VisibleRange.Top + ActiveWindow.VisibleRange.Height - 5
.Left = ActiveWindow.VisibleRange.Left + ActiveWindow.VisibleRange.Width - .Width - 5
End With
End Sub
Here is the idea that I put across the comment earlier today :) Typically we can get a Floating User Form by setting the Modal property of the form to be 0 which is indeed a Modeless state.
Basic Points to consider:
Look & Feel of the form to make it look like a Button (Not show title bar/Not Resizable/
Hidden Close Button etc)
Setting the position of the Button
Which Event should trigger the form-button (WorkBook Open)
What would you do with Form Initialize Event
Whcih Events should keep it stick to the same position alive
Further Points to consider:
You might only want to keep this button vissible for the workbook you are working, and if you open another instance of a workbook, do you still want to keep the button
If you minimize the Excel Window instance, how do you plan to manage the state of the button and keep it visible
Post about keep displaying a form even the workbook is minimized.
One other great reference I happend to see, (little bit technical) but worth the shot - at least to get to know the certain properties/methods that you could make use: Extending VBA User Form Control.
The article include the following info, and please note the last line as well :)
They give you access to capabilities that are not available from VBA or from the objects (UserForms, Workbooks, etc.,) that make up a VBA Project. When you call an API, you are bypassing VBA and calling directly upon Windows. This means that you do not get the safety mechanisms such as type checking that VBA normally provides. If you pass an invalid value to an API or (a very common mistake) use a ByRef parameter instead of a ByVal parameter, you will most likely completely and immediately crash Excel and you will lose all your unsaved work. I recommend that until you are confident that your API calls are solid you save your work before calling an API function.
Add new Row on the beginning of your WorkSheet and set your button on it, then:
Freeze Top Row
Right click → properties → placement → change to 3.