onmouseover event

K

Kalle

Hi!

I have this code and it works but it should be nice if the macro2 could
run with an onmouseover event. Is this possible? If it is, is it also
possible to get the old text with somthing like onmouse out?

Sub Macro3()

ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 346.5,
105#, _
100.5, 63#).Select
Selection.Characters.Text = "Text"
Selection.Name = "MyTextBox"
Selection.OnAction = "Macro2" 'insert new text
End Sub

Sub Macro2()
ActiveSheet.Shapes("MyTextBox").Select
Selection.Characters.Text = "New Text"
Range("F20").Select
End Sub

Thanks in advance
 
N

Neptune Dinosaur

The various "built in" mouse events are only coded to work with objects that
are on a User Form (as distinct from objects drawn on a worksheet).

User forms are good fun and very functional and they give your application a
professional look, which can be handy if other people are using it. Worth
considering .....
 
K

kalle

Thanks for your answer.

You say that mouse events only works in userforms but if I insert a
control in a worksheet? Does a control have the same mouse evnts in a
worksheet?

I use userforms in this project but it should be nice if I can use a
mouse event in one of my worksheets.

I need something transparent that start a event macro. I try to insert
label by code but I can't set it to transparet. If that is possible that
should solve my problem.

Regards
Kalle
 
N

Neptune Dinosaur

I'm not 100% sure I understand exactly what you are trying to achieve, but as
far as I have ever seen, there is no way to use a Mouse event on a worksheet,
only on user forms. If I were doing what I think you are trying to do, I
would activate macro2 using the RightClick or DoubleCLick event, which WILL
work on a worksheet.
I would restrict the operation of the event procedure to a particular cell
or group of cells (using the "Target" parameter in the event) and use "Cancel
= True" so that the normal default right-click event would not also occur.
You could put the desired code in the Event procedure itself or have it call
the code from a separate Sub.
In the cell(s) that you want to use as a trigger, you could put some text
like "Run Text Procedure (R-Click)" as a visual cue. Exactly how or whether
you do that would depend on whether other people are going to be using your
app and (therefore) whether a visual cue is necessary.
I do a lot of this "event driven" stuff in apps that are used by 50 or 60
people who have varying levels of IT savvy. You need to put a lot of thought
into it, mainly on two grounds (1) You have to provide a strong intuitive
interface for the less IT-savvy people without treating the "ITsmart" people
like dummies (2) Sheet events add layers of complexity to the whole project
and can have unintended consequences which then need solutions that require
another level of complexity. But the event-driven app can be extremely
"smart" and user-friendly if you get it right and stay on top of the
complexities.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top