Como puedo hacer para que esta macro funcione en cualquier libro que tenga activo y haga referencia a las hojas que tenga ese libro?
en el modulo ThisWorkbook:
Public Sub Navigate()
Dim ac As CommandBarButton
Set ac = Application.CommandBars.ActionControl
Sheets(ac.Caption).Select
Set ac = Nothing
End Sub
Private Sub Workbook_Deactivate()
Application.CommandBars("Cell").Reset
End Sub
Private Sub Workbook_Activate()
CreatePopUp
End Sub
en un modulo normal:
Sub CreatePopUp() ' creates the custom popup menu
Dim cb As CommandBar, i As Integer
Set cb = Application.CommandBars("Cell")
With cb
.Reset
For i = 1 To Sheets.Count
With .Controls.Add(Type:=msoControlButton)
.OnAction = "ThisWorkBook.Navigate"
.FaceId = 0
.Caption = Sheets(i).Name
.TooltipText = "Ir a esta hoja: " & Sheets(i).Name
End With
Next
End With
Set cb = Nothing
End Sub
en el modulo ThisWorkbook:
Public Sub Navigate()
Dim ac As CommandBarButton
Set ac = Application.CommandBars.ActionControl
Sheets(ac.Caption).Select
Set ac = Nothing
End Sub
Private Sub Workbook_Deactivate()
Application.CommandBars("Cell").Reset
End Sub
Private Sub Workbook_Activate()
CreatePopUp
End Sub
en un modulo normal:
Sub CreatePopUp() ' creates the custom popup menu
Dim cb As CommandBar, i As Integer
Set cb = Application.CommandBars("Cell")
With cb
.Reset
For i = 1 To Sheets.Count
With .Controls.Add(Type:=msoControlButton)
.OnAction = "ThisWorkBook.Navigate"
.FaceId = 0
.Caption = Sheets(i).Name
.TooltipText = "Ir a esta hoja: " & Sheets(i).Name
End With
Next
End With
Set cb = Nothing
End Sub