How can I enable highlight when mouse over into VBA? - vba

how can I enable highlight when mouse over into VBA? I write a marco into VBA, that after creating a new shape the shape should be enabled highlight when mouse over. Maybe with color?
Thank you
argonist

Your macro would need to run on a specific event. So in Powerpoint you have options such as:
MouseDown
MouseMove
MouseUp
You can hit the F1 key to tell you exactly which event does what.
In VBA there is no event called 'MouseOver' so you need to improvise such as using a 'MouseMove' event to change the colour when you hover over it, and then maybe the pages 'MouseMove' event to change it back to the default colour when you move the mouse onto something else.
You should be able to find all of these events in the drop down list for the object in the Visual Basic window
Another option rather than using VBA is to play around with powerpoints animations and effects which may get you the same result.

I found the simply way.
myshape.ActionSettings(ppMouseOver).AnimateAction = msoTrue
But I cannot change the color and the line size. That is enough for me. Thank you.

Try this one on ActiveX picture attach in slide (code run in show mode)
'zmien_w_trybie_prezentacji - VBATools.pl
Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call kolor2(Image1)
End Sub
Sub kolor2(osh As Image)
If osh.BackColor = 255 Then _
osh.BackColor = 13998939 Else _
osh.BackColor = 255
End Sub

Related

How to use an event as If statement condition

I want to write a code for my form that when user clicks on each of text boxes to enter the data, textbox background change to green.
Something like this - in form current event:
Dim c as control
For each c In me.controls
If c.OnClick then
C.backcolor= vbGreen
C.tag="clicked"
End If
If c.AfterUpdate and c.tag="clicked" then
C.backcolor= vbWhite
C.tag=""
Next c
How can I find out when an event is triggered?
You will use WithEvents for that. This is poorly documented, but an example can be found in my project (too much code to post here):
VBA.ModernTheme
Full documentation and further links are in my article on the project:
Create Windows Phone Colour Palette and Selector using WithEvents
You can create two functions in your form code as follows:
Private Function SetBackColor()
Me.ActiveControl.BackColor = vbGreen
End Function
Private Function ResetBackColor()
Me.ActiveControl.BackColor = vbWhite
End Function
Then set the On Got Focus property of all the text boxes to =SetBackColor()
and the On Lost Focus property of all text boxes to =ResetBackColor()
This can be done easily by selecting all text boxes and write the property once and it will apply to all of them (no need to repeat the writes).
This will work whenever the user tries to edit any text box even if it was reached by TAB or ENTER buttons not only mouse click.

Ellipsis Textbox for VBA Userform File Select

I am trying to create a path selection user interface for an extensive VBA program I've been working on, but I can't seem to get the ellipsis textbox that I'd like. This is a very common feature, especially in option tables. This is an example of what I'd like to get, straight from the VBA Options panel:
I would LOVE to find a way to get the same functionality in a Userform. The only solution that I've found thus far is to use a combo box with the ellipsis arrow option enabled. However, there doesn't seem to be an apparent way to use the activation of the combo box arrow to run a dialog box, nor does there seem to be a way to make it look UNLIKE a combo box. Last resort I use a button below the text box, but I'd really prefer a less-bulky way of doing this.
Any solution would be greatly appreciated.
The only solution that I've found thus far is to use a combo box with
the ellipsis arrow option enabled. However, there doesn't seem to be
an apparent way to use the activation of the combo box arrow to run a
dialog box, nor does there seem to be a way to make it look UNLIKE a
combo box
Your suggestion does work, and it is surely less complex and more elegant than having two controls work together, Button + Textbox.
A Combo can achieve perfectly the desired feature, in the following way.
1) In design mode, set the button style to Ellipsis
DropButtonStyle = fmDropButtonStyleEllipsis
And eventually, make the ellipsis show up only when the combo is entered, by setting the design-time property:
ShowDropButtonWhen = ShowDropButtonWhenFocus
2) If needed, you can set other design-time properties to have some look and feel. The defaults look pretty good however.
3) Add the following handler to the parent userform. The snippet simulates the launching of a dialog and getting a new value or cancelling. It does not show any dropdown window. (but you still have control over that: if you want to show it according to some condition, you still can call the method ComboBox1.DropDown)
Private Sub ComboBox1_DropButtonClick()
' The following two lines avoid to call the routine twice, at entry and at exit
Static i As Integer
i = (i + 1) Mod 2: If i = 0 Then Exit Sub
With ComboBox1
s = InputBox("enter some text", , .Value) '<~~ simulates any dialog
If s <> "" Then .Value = s
SendKeys ("{Enter}") '<~~ to close immediately the dropdown window
End With
End Sub
Try it ;)
Not only do ComboBoxes have Drop Buttons, so do TextBoxes (as do Excel's RefEdit controls). Even though you can't access the Textbox's Drop Button at design time, you can do so at runtime. Using a textbox avoids having to deal with the dropped down list of a combobox.
Given a textbox named TextBox1, the following code will provide the desired ellipsis drop button:
Private Sub UserForm_Initialize()
With Me.TextBox1
.DropButtonStyle = fmDropButtonStyleEllipsis
.ShowDropButtonWhen = fmShowDropButtonWhenAlways
End With
End Sub
Then use the DropButtonClick event of the textbox to perform whatever action you want:
Private Sub TextBox1_DropButtonClick()
'' Code here to do what you need
End Sub
I have an extensive example at Alternative to Excel’s Flaky RefEdit Control that uses a textbox with a "Reduce" drop button to replicate the functionality of Excel's unreliable RefEdit controls.

Excel Userform Textbox Constant Set Focus

First of all I would like to thank all of you guys. Maybe you did not notice but you help me to grasp VBA to some level from scratch. I am still in learning process so I may be missing something really simple, please be gentle :)
First of all I would like to give a small backgroud update about my issue. I have been writing a small program to scan incoming parts to my work to be able to keep inventory status. Latest look of the program is like below:
And numbers on the picture are my nightmares lately:
1. Scanned Part Number: This is the textbox where scanner inputs the value. After I receive the input I immidietly convert that data to a variable and clear the textbox value as below:
Private Sub PN_CurrentScan_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
EnteredPN = Replace(PN_CurrentScan.Value, Chr(32), "", 1) '<---PN_CurrentScan is the name of text box
EnteredPN = Left(EnteredPN, 12)
PN_CurrentScan.Value = ""
After making some corrections on the scanned data I basically write it to a sheet in the workbook. Then I also have a pivot table in the same workbook which uses this scanned data as source and counts how many parts scanned from each part number.
2. Current Status: This ListBox contains all the part numbers scanned (Coming from the pivot table mentioned above) and waiting to be scanned (Coming from another worksheet). Then it refreshes it self every time a new part is scanned.
3. ListBox Scroll Bar: Since I have very long part number list it is not possible for me to fit everything on the screen that is why listbox creates this scroll bar.
Enough with the background I think :)
So if we come to my concern. Since my collages using cordless scanner to do this operation sometimes they don't have the chance to see the screen so they can not understand if the cursor is on the "Scanned Part Number Text Box" or not. That is why I need focus to be on that box no matter what happens (Of course we can not do anything if warehouse burns down, earth quake or tsunami hits the place but let do not think about those).
WHAT I HAVE TRIED:
First of all I disabled all the remaining objects from properties window
Then I diabled tab stops of all controls:
Dim contr As Control
For Each contr In ScannerInterface.Controls
On Error Resume Next
contr.TabStop = False
Next
ScannerInterface.PN_CurrentScan.TabStop = True
Added setfocus property to all button clicks:
Me.PN_CurrentScan.SetFocus
Added setfocus property to listbox click:
Private Sub CurrentStatus_List_Click()
Me.PN_CurrentScan.SetFocus
End Sub
Added set focus to enter and exit events of listbox however this did not work:
Private Sub CurrentStatus_List_Enter()
Me.PN_CurrentScan.SetFocus
End Sub
Private Sub CurrentStatus_List_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.PN_CurrentScan.SetFocus
End Sub
So, with all these counter measures I have managed to improve up to somepoint, only concern remaining is when I click on the scroll bar next to the listbox, text box lose focus and without clicking in the textbox I could not manage to set the focus again. I tried all events with listbox non of them worked. Is there any way to solve this problem or do I need to deal with this? Thanks in advance for your supports.
SOLUTION:
Thanks to #Rory we have managed to solve my problem. As he noticed and explained in the answer below, both my textbox and listbox were in frames. I have tried several setfocus options but I always gave the focus to the textbox. However, solution was to give the focus to the frame which was containing the target textbox:
Private Sub CurrentStatus_Frame_Enter() '<-- Enter event of the frame which contains listbox
Me.PN_CurrentScan.SetFocus '<-- Setfocus to target textbox
Me.Scanned_Frame.SetFocus '<-- Setfocus to frame which contains target textbox
End Sub
Having (eventually) noticed that both of your controls are inside container Frame controls, you can actually use the Enter event of the Frame that contains the listbox to set focus to the Frame that contains the textbox, rather than to the textbox itself.

Custom Design of an Excel Textbox VBA

Well I was wondering whether we can somehow create custom looking text boxes that act as an input box and is linked to VBA.
As far as I am aware the standard procedure would entail adding an ActiveX Textbox Control and then using the TextBox1_Change event to add the code as to what needs to happen when the user enters something in to.
Sadly the look of the default textbox isn't matching the way I want by spreadsheet to look. So is there any way to change how it looks or have something replace it while serving the same purpose?
One thing I could think of and have tried is inserting a shape (blue):
Shape http://im52.gulfup.com/qD2F0B.png
I can get the text that is in the shape using VBA by:
InputText = Shapes("Rounded Rectangle 1").TextFrame.Characters.Text
But I don't suppose there is a way to detect a change of shape text event?
Suggestions / Workarounds are welcome!
Thanks
There are limitations on what you can change on an ActiveX TextBox, such as Font/Color/Border/SpecialEffects, but the basic rectangle shape cannot be changed.
However you can make the TextBox transparent by BackStyle property and group it to a shape (bring the TB forward) and still use the TextBox1_Change method for changes.
If you need to access the value in the TextBox somewhere else, a quick way is to use TextBox1.LinkedCell and below to set the value to a cell, or a Named Range.
Private Sub TextBox1_Change()
' Same Sheet as TextBox1
ActiveSheet.Range(TextBox1.LinkedCell).Value = TextBox1.Value
' Or Below for Named Range
ThisWorkbook.Names(TextBox1.LinkedCell).RefersToRange.Value = TextBox1.Value
End Sub

Hot make a mouse leave event in vb6 over a image

I have a image for which i have written code in MouseMove to higlight it. this is being done what i want is to when the mouse leaves image the highlights go away but i cant seem to find any event which will do that. i am working in visual basic 6.0. i have tried the mouseup and down event but they dont match my req.
Thanks
There isn't an event like that in VB6 (although VB.Net has MouseLeave). You will need to do something in the MouseMove event of the form (and perhaps any container controls too).
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Unhighlight the image'
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Highlight the image'
End Sub
There is a great little ocx control for this exact purpose written by Marco Bellinaso, a well respected author and a big contributor of good content to the VB community in his time.
The control is called the "MB MouseHelper". You can download it from devx.com at http://www.devx.com/vb2themax/CodeDownload/19735.
alt text http://img25.imageshack.us/img25/3985/screencap20100809110523.jpg
There are two problems with using VB's built in MouseMove event that make this control useful:
You have to catch all the places where the user could put the mouse when it leaves your image, like the form or another control or a nearby label
And the user can still move the mouse very quickly, jumping over any part of the window that would trigger the MouseMove event that unhighlights your image
You can also put the image you want to simulate the mouseleave event inside a bigger picture. That way, when you leave the inner picture (smaller) you will hit the mousemove event of the outer picture. Also, this works if you use a frame or label instead of another picture
You can always subclass the control. Here's an article that describes how to do it.
One thing to care about if you use the mouseMove event is to raise a flag when you are IN the control you want to highlight and raise another when you are OUT so as not to repeat the same action on each mouse xy change
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' if imageIsHighlighted = true then
' Unhighlight the image'
' imageIsHighlighted = false
' end if
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' if imageIsHighlighted = false then
' Highlight the image'
' imageIsHighlighted = True
' end if
End Sub