Saltar al contenido

Como unir dos Workbook_Open


ULISES

Recommended Posts

Buenas tardes compañeros

Primero que todo un saludo y buenos deseos

Tengo dos macros diferentes que tienen dos Workbook_Open y no se como hacer para que funcionen correctamente ya que individual hacen su trabajo pero juntos se genera un error que no permite mostrar las demás hojas del archivo a menos que se guarde el archivo otra ves, lo cual no debería de ser ya que tiene que ser automático al abrir el archivo con las macros activadas.

Este seria uno

Option Explicit
Const WelcomePage = "Macros"

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.EnableEvents = False
With ThisWorkbook
If Not .Saved Then
Select Case MsgBox("Desea guardar los cambios realizados a '" & .Name & "'?", _
vbYesNoCancel + vbExclamation)
Case Is = vbYes

Call CustomSave
Case Is = vbNo
Case Is = vbCancel
Cancel = True
End Select
End If
If Not Cancel = True Then
.Saved = True
Application.EnableEvents = True
.Close savechanges:=False
Else
Application.EnableEvents = True
End If
End With
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Application.EnableEvents = False

Call CustomSave(SaveAsUI)
Cancel = True

Application.EnableEvents = True
ThisWorkbook.Saved = True
End Sub

Private Sub Workbook_Open2()

Application.ScreenUpdating = False
Call ShowAllSheets
Application.ScreenUpdating = True
End Sub

Private Sub CustomSave(Optional SaveAs As Boolean)
Dim ws As Worksheet, aWs As Worksheet, newFname As String

Application.ScreenUpdating = False
Set aWs = ActiveSheet
Call HideAllSheets
If SaveAs = True Then
newFname = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls")
If Not newFname = "False" Then ThisWorkbook.SaveAs newFname
Else
ThisWorkbook.Save
End If
Call ShowAllSheets
aWs.Activate
Application.ScreenUpdating = True
End Sub

Private Sub HideAllSheets()
Dim ws As Worksheet
Worksheets(WelcomePage).Visible = xlSheetVisible
For Each ws In ThisWorkbook.Worksheets
If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVeryHidden
Next ws

Worksheets(WelcomePage).Activate
End Sub

Private Sub ShowAllSheets()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVisible
Next ws
Worksheets(WelcomePage).Visible = xlSheetVeryHidden
End Sub
[/HTML]

Y este el otro

[HTML]Private Sub Workbook_Open()
'Desactivamos las teclas de cancelación de macros
Application.EnableCancelKey = xlDisabled
'Eventos que se producen al abrir el libro:
'si le han cambiado el nombre al fichero
'mostraremos un mensaje, y cerraremos
'el libro
If ThisWorkbook.Name <> "Habilitar Macros.xls" Then
'Cargamos el UserForm
Notificacion_de_Seguridad.Show
End If
End Sub
[/HTML]

Agradeceria el apoyo que me puedan prestar

Saludos

Habilitar Macros.rar

Enlace a comentario
Compartir con otras webs

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

×
×
  • Crear nuevo...

Información importante

Echa un vistazo a nuestra política de cookies para ayudarte a tener una mejor experiencia de navegación. Puedes ajustar aquí la configuración. Pulsa el botón Aceptar, si estás de acuerdo.