jueves, 16 de febrero de 2012

CREAR ACCION MENU CONTEXTUAL (BOTON DERECHO)



Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call DeleteFromCellMenu

End Sub

Sub AddToCellMenu()
Dim ContextMenu As CommandBar
Dim MySubMenu As CommandBarControl

'**************esto se ejecuta si no hace la funcion de before close********************
'Eliminar los controles de primera para evitar duplicados.
'Llama a DeleteFromCellMenu
'**************esto se ejecuta si no hace la funcion de before close********************

'Establecer ContextMenu al menú contextual de la célda.
Set ContextMenu = Application.CommandBars("Cell")

'Añadir un botón integrado (guardar = 3) en el menú contextual de la célda.
ContextMenu.Controls.Add Type:=msoControlButton, ID:=3, before:=2

'Añadir un botón personalizado en el menú contextual de la célda.
With ContextMenu.Controls.Add(Type:=msoControlButton, before:=1)
.OnAction = "ChooseSheet" '''' asi se llama la macro va y busca la rutina
.FaceId = 516
.Caption = "Ubicación Hoja"
.Tag = "My_Cell_Control_Tag"
End With

End Sub

Sub DeleteFromCellMenu()
Dim ContextMenu As CommandBar
Dim ctrl As CommandBarControl

'Establecer ContextMenu al menú contextual de la célda.
Set ContextMenu = Application.CommandBars("Cell")

'Eliminar los controles personalizados con el tag: My_Cell_Control_Tag.
For Each ctrl In ContextMenu.Controls
If ctrl.Tag = "My_Cell_Control_Tag" Then
ctrl.Delete
End If
Next ctrl

'Eliminar la costumbre incorporada en el botón Guardar.
On Error Resume Next
ContextMenu.FindControl(ID:=3).Delete
On Error GoTo 0
End Sub



Private Sub Workbook_Open()
Call AddToCellMenu
End Sub

miércoles, 15 de febrero de 2012

IR A UNA HOJA POR MEDIO DE MENU


METODO 1

Sub Goanysheet()

myShtees = ActiveWorkbook.Sheets.Count
For i = 1 To myShtees
myList = myList & i & " - " & ActiveWorkbook.Sheets(i).Name & " " & vbCr
Next i
Dim mihojita As Single
mihojita = InputBox("Selecciones la hoja a la que desea ir." & vbCr & vbCr & myList)
Sheets( myShtees ).Select
End Sub


METODO 2 ******para mi el mejor******

Sub ChooseSheet()

Dim ws As Worksheet
Application.CommandBars("Workbook Tabs").ShowPopup

Set ws = ActiveSheet

End Sub