Excel VBA - How to Run a Macro Using MouseMove Event

  Рет қаралды 5,089

The World Of Algorithms

The World Of Algorithms

2 жыл бұрын

💡 Source Code:
Private Sub UserForm_Activate()
With Me
.Height = Application.Height
.Width = Application.Width
.Left = Application.Left
.Top = Application.Top
End With
End Sub
' act_tb, prev_tb and next_tb are the names of the text boxes
Sub MouseMoveForBtns(ByVal btn_i As Byte)
Dim min_index As Byte, max_index As Byte, i As Byte
min_index = 1
max_index = 10
For i = min_index To max_index
With Me.Controls("CommandButton" & i)
If i = btn_i Then
.BackColor = vbYellow
.ForeColor = vbBlack
act_tb = Controls("CommandButton" & i).Caption
If i - 1 ◀ min_index Then
prev_tb = ""
prev_tb.BackStyle = fmBackStyleOpaque
next_tb = Controls("CommandButton" & i + 1).Caption
ElseIf i + 1 ▶ max_index Then
prev_tb = Controls("CommandButton" & i - 1).Caption
next_tb = ""
next_tb.BackStyle = fmBackStyleOpaque
Else:
prev_tb.BackStyle = fmBackStyleTransparent
next_tb.BackStyle = fmBackStyleTransparent
prev_tb = Controls("CommandButton" & i - 1).Caption
next_tb = Controls("CommandButton" & i + 1).Caption
End If
Else:
.BackColor = &H800080
.ForeColor = vbWhite
End If
End With
Next i
End Sub
Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call MouseMoveForBtns(1)
End Sub
Private Sub CommandButton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call MouseMoveForBtns(2)
End Sub
Private Sub CommandButton3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call MouseMoveForBtns(3)
End Sub
Private Sub CommandButton4_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call MouseMoveForBtns(4)
End Sub
Private Sub CommandButton5_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call MouseMoveForBtns(5)
End Sub
Private Sub CommandButton6_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call MouseMoveForBtns(6)
End Sub
Private Sub CommandButton7_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call MouseMoveForBtns(7)
End Sub
Private Sub CommandButton8_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call MouseMoveForBtns(8)
End Sub
Private Sub CommandButton9_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call MouseMoveForBtns(9)
End Sub
Private Sub CommandButton10_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call MouseMoveForBtns(10)
End Sub
------------------------------------------------------------------------------------------
Buy a Cofee ☕ for theworldofalgorithms: ko-fi.com/theworldofalgorithms
🥰Thank you for the donation. I am deeply grateful for your help!🥰
------------------------------------------------------------------------------------------
#excelvbatutorial
#msexcel
#msexceltutorial
#msexcelcourse
#vba
#vbatutorial
#excelvba
#excelvbatutorial
#microsoftexceltutorial
#tutorial
#exceltutorial
#excelvbatutorial
#vbatutorial
#mousemoveevent
#mousemove
#vbamousemoveevent
#commandbutton
#label
#textbox
#vbacommandbutton
#vbalabel
#vbatextbox
#algorithm
#changebuttoncolor
#menu
#menubar
#vbamenubar
#excelvbamenubar
#runamacro
#macro
#vbamacro
#excelvbamacro
#advancedexcel

Пікірлер: 1
@indianmonster1445
@indianmonster1445 Жыл бұрын
So Amazing Sir, I has Trying Command Button Visible when i select cell (A1: A20) after Visible button in Left Side ............ How to possible pleased Arrange Coding
Excel VBA - ArrayList (Sort, Reverse and Clone Methods)
14:39
The World Of Algorithms
Рет қаралды 4,7 М.
- А что в креме? - Это кАкАооо! #КондитерДети
00:24
Телеканал ПЯТНИЦА
Рет қаралды 6 МЛН
Scary Teacher 3D Nick Troll Squid Game in Brush Teeth White or Black Challenge #shorts
00:47
Khó thế mà cũng làm được || How did the police do that? #shorts
01:00
Schedule Excel Macro to Run Automatically at certain time
10:59
Excel Destination
Рет қаралды 76 М.
Watch these 28 minutes if you want to become an Advanced VBA user...
29:01
Excel Macro Mastery
Рет қаралды 50 М.
5 VBA Hacks Everyone Should Know in 2021
11:20
Excel Macro Mastery
Рет қаралды 90 М.
Excel VBA: The Magic of the Worksheet Change Event
14:24
Excel Macro Mastery
Рет қаралды 70 М.
Creating Classes in VBA
10:19
Jennifer Garth
Рет қаралды 17 М.
Tutorial 1 : Scraping data from website using Excel macro(vba)
6:21
Extreme Automation - Kamal Girdher
Рет қаралды 146 М.
MouseOver effect to your Excel Dashboards
17:14
Sergio Alejandro Campos - EXCELeINFO
Рет қаралды 21 М.
Next Empty Row Trick in Excel VBA & Macros
10:36
TeachExcel
Рет қаралды 52 М.
- А что в креме? - Это кАкАооо! #КондитерДети
00:24
Телеканал ПЯТНИЦА
Рет қаралды 6 МЛН