.
En esta entrega de ejemplos de macro te presento una macro que crea un menú que se desplaza a medida que se hace scroll, quedando siempre la barra de menú siempre visible, es una forma sencilla de salvar la situación que VBA no tiene un evento scroll.
Anteriormente se presentó otros post parecidos que quizás sean de interés como por ejemplo: Como simular scroll seleccionando celda y desplazando botón automaticamente y Como desplazar botón en forma practicamente automática al hacer scroll con la rueda del mouse.
Recomiendo leer un excelente libro sobre Excel que te ayudará operar las planillas u hojas de cálculo, haz click acá, si quieres aprender sobre Excel, en inglés, entonces debes hacer click here. Si lo que necesitas es aprender o profundizar sobre la programación de macros con VBA este es unos de los mejores cursos on line que he visto en internet.
El vídeo que sigue muestra una explicación más detallada y gráfica de la macro presentada, recomiendo observar para una más fácil comprensión de la macro; suscribe a nuestra web desde la parte superior derecha de la página ingresando tu mail y a nuestro canal de You Tube para recibir en tu correo vídeos explicativos sobre macros interesantes, como por ejemplo formulario que crea un listado de todas las hojas para poder luego seleccionarlas, buscar en listbox mientras escribes en textbox, ordenar hojas libro excel por su nombre, conectar Excel con Access y muchos ejemplos más.
if (payload.eventType == ‘subscribe’) {
// Add code to handle subscribe event.
} else if (payload.eventType == ‘unsubscribe’) {
// Add code to handle unsubscribe event.
}
if (window.console) { // for debugging only
window.console.log(‘YT event: ‘, payload);
}
}
Código que se inserta en un módulo
Public Declare Function FindWindow Lib «User32» Alias «FindWindowA» (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowLong Lib «User32» Alias «GetWindowLongA» (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib «User32» Alias «SetWindowLongA» (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function DrawMenuBar Lib «User32» (ByVal hwnd As Long) As Long
Sub EliminarTitulo(MeCaption)
Dim lSty As Long
Dim hMenu As Long
Dim mhWndForm As Long
mhWndForm = FindWindow(«ThunderDFrame», MeCaption)
lSty = GetWindowLong(mhWndForm, -16)
lSty = lSty And Not &HC00000
SetWindowLong mhWndForm, -16, lSty
DrawMenuBar mhWndFormEnd Sub
Código que se inserta en un Formulario
Dim FormX, FormY, mycab
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub
Private Sub CommandButton5_Click()
UserForm1.Show
End Sub
Private Sub CommandButton8_Click()
UserForm1.Show
End Sub
Private Sub CommandButton9_Click()
UserForm1.Show
End Sub
Private Sub CommandButton3_Click()
UserForm1.Show
End Sub
Private Sub CommandButton4_Click()
UserForm1.Show
End Sub
Private Sub CommandButton6_Click()
UserForm1.Show
End Sub
Private Sub CommandButton2_Click()
UserForm1.Show
End Sub
Private Sub CommandButton7_Click()
Unload UserForm4
End Sub
Private Sub Label73_Click()
Application.ScreenUpdating = False
UserForm4.Height = 5
Range(«A2»).EntireRow.Hidden = True
Range(«A1»).RowHeight = 28.5
Range(«A1»).Font.Size = 30
Me.Label73.Visible = False
Me.Label74.Visible = True
Application.ScreenUpdating = True
End Sub
Private Sub Label74_Click()
Application.ScreenUpdating = False
UserForm4.Height = 48.2
Range(«A2»).EntireRow.Hidden = False
Range(«A1»).RowHeight = 30 ‘57.75
Range(«A1»).Font.Size = 50
Me.Label73.Visible = True
Me.Label74.Visible = False
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Initialize()
Dim sql As String, I As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
EliminarTitulo Me.Caption
Me.Height = 48.2
Me.Top = 200
Me.Left = 18.75
Me.Width = 700 ‘420
Me.Label74.Visible = False
UserForm4.ComboBox1 = «Caratula»
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
If Button = 1 Then FormX = x: FormY = Y
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
If Button = 1 Then Me.Left = Me.Left + (x – FormX): Me.Top = Me.Top + (Y – FormY)
End Sub
Public Declare Function GetWindowLong Lib «User32» Alias «GetWindowLongA» (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib «User32» Alias «SetWindowLongA» (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function DrawMenuBar Lib «User32» (ByVal hwnd As Long) As Long
Sub EliminarTitulo(MeCaption)
Dim lSty As Long
Dim hMenu As Long
Dim mhWndForm As Long
mhWndForm = FindWindow(«ThunderDFrame», MeCaption)
lSty = GetWindowLong(mhWndForm, -16)
lSty = lSty And Not &HC00000
SetWindowLong mhWndForm, -16, lSty
DrawMenuBar mhWndForm
End Sub
Código que se inserta en un Formulario
Dim FormX, FormY, mycab
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub
Private Sub CommandButton5_Click()
UserForm1.Show
End Sub
Private Sub CommandButton8_Click()
UserForm1.Show
End Sub
Private Sub CommandButton9_Click()
UserForm1.Show
End Sub
Private Sub CommandButton3_Click()
UserForm1.Show
End Sub
Private Sub CommandButton4_Click()
UserForm1.Show
End Sub
Private Sub CommandButton6_Click()
UserForm1.Show
End Sub
Private Sub CommandButton2_Click()
UserForm1.Show
End Sub
Private Sub CommandButton7_Click()
Unload UserForm4
End Sub
Private Sub Label73_Click()
Application.ScreenUpdating = False
UserForm4.Height = 5
Range(«A2»).EntireRow.Hidden = True
Range(«A1»).RowHeight = 28.5
Range(«A1»).Font.Size = 30
Me.Label73.Visible = False
Me.Label74.Visible = True
Application.ScreenUpdating = True
End Sub
Private Sub Label74_Click()
Application.ScreenUpdating = False
UserForm4.Height = 48.2
Range(«A2»).EntireRow.Hidden = False
Range(«A1»).RowHeight = 30 ‘57.75
Range(«A1»).Font.Size = 50
Me.Label73.Visible = True
Me.Label74.Visible = False
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Initialize()
Dim sql As String, I As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
EliminarTitulo Me.Caption
Me.Height = 48.2
Me.Top = 200
Me.Left = 18.75
Me.Width = 700 ‘420
Me.Label74.Visible = False
UserForm4.ComboBox1 = «Caratula»
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
If Button = 1 Then FormX = x: FormY = Y
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
If Button = 1 Then Me.Left = Me.Left + (x – FormX): Me.Top = Me.Top + (Y – FormY)
End Sub
.
If this post was helpful INVITE ME A COFFEE and so help keep up the page, CLICK to download free example.
Si te gustó por favor compártelo con tus amigos
If you liked please share it with your friends