Como adaptar una macro que ya tengo

Necesito adaptar estas macros

Public boton
'
Sub boton_guardar()
'Por.Dante Amor
    boton = True
    ActiveWorkbook.Save
    MsgBox "Archivo guardado", vbInformation, "GUARDAR"
End Sub

Pon el siguiente código en los eventos de thisworkbook

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Por.Dante Amor
    If SaveAsUI Or boton = False Then
        MsgBox "Solamente puedes guardar presionando el botón de Guardar ", vbExclamation
        Cancel = True
        Exit Sub
    End If
    boton = False
End Sub

con esta

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
'If ActiveSheet.Range("H18") = "Ingrese Legajo primero" Then
'MsgBox ("Por favor ingrese o verifique el numero de legajo")
'Range("E18").Select
'Else
'Lunes
'If ActiveSheet.Range("J22") = "SI" Then
'If ActiveSheet.Range("E83") = "" Or ActiveSheet.Range("F83") = "" Then
'lunes = "lunes, "
'MsgBox ("Falta seleccionar menu del Lunes")
'End If
'End If
'Martes
'If ActiveSheet.Range("J34") = "SI" Then
'If ActiveSheet.Range("G83") = "" Or ActiveSheet.Range("H83") = "" Then
'martes = "martes, "
'MsgBox ("Falta seleccionar menu del Martes")
'End If
'End If
'Miercoles
'If ActiveSheet.Range("J46") = "SI" Then
'If ActiveSheet.Range("I83") = "" Or ActiveSheet.Range("J83") = "" Then
'miercoles = "miercoles, "
'MsgBox ("Falta seleccionar menu del Miercoles")
' End If
' End If
'Jueves
'If ActiveSheet.Range("J58") = "SI" Then
'If ActiveSheet.Range("K83") = "" Or ActiveSheet.Range("L83") = "" Then
'jueves = "jueves, "
'MsgBox ("Falta seleccionar menu del Jueves")
'End If
'End If
'Viernes
'If ActiveSheet.Range("J70") = "SI" Then
'If ActiveSheet.Range("M83") = "" Or ActiveSheet.Range("N83") = "" Then
'viernes = "viernes, "
'MsgBox ("Falta seleccionar menu del Viernes")
'End If
'End If
'If lunes = "lunes, " Or martes = "martes, " Or miercoles = "miercoles, " Or jueves = "jueves, " Or viernes = "viernes, " Then
'Alerta de los dias no completados
'MsgBox ("Falta seleccionar menu ó postre del día: " + lunes + martes + miercoles + jueves + viernes)
'If a = vbNo Then Cancel = True
'End If
'MsgBox ("La celda e6 NO es NUll")
'End If
End Sub

Sub GuardarCopia()
'Por.Dante Amor
If ActiveSheet.Range("H18") = "Ingrese Legajo primero" Then
MsgBox ("Por favor ingrese o verifique el numero de legajo")
Range("E18").Select
Exit Sub
End If
Dim verif As Boolean
verif = VerificarPedido()
If verif = False Then
Exit Sub
Else
ruta = ThisWorkbook.Path & "\"
Set h1 = Sheets("menu")
celda = "H18"
'
nombre = h1.Range(celda) & "_" & h1.Range("C18") & ".xlsm"
ThisWorkbook.SaveCopyAs ruta & nombre
MsgBox "Copia guardada en " & ruta + nombre, vbInformation, ""
Application.ActiveWorkbook.Save
Application.ActiveWorkbook.Close
End If
End Sub

Function VerificarPedido() As Boolean
'Lunes
If ActiveSheet.Range("J22") = "SI" Then
If ActiveSheet.Range("E83") = "" Or ActiveSheet.Range("F83") = "" Then
lunes = "lunes, "
'MsgBox ("Falta seleccionar menu del Lunes")
End If
End If
'Martes
If ActiveSheet.Range("J34") = "SI" Then
If ActiveSheet.Range("G83") = "" Or ActiveSheet.Range("H83") = "" Then
martes = "martes, "
'MsgBox ("Falta seleccionar menu del Martes")
End If
End If
'Miercoles
If ActiveSheet.Range("J46") = "SI" Then
If ActiveSheet.Range("I83") = "" Or ActiveSheet.Range("J83") = "" Then
miercoles = "miercoles, "
'MsgBox ("Falta seleccionar menu del Miercoles")
End If
End If
'Jueves
If ActiveSheet.Range("J58") = "SI" Then
If ActiveSheet.Range("K83") = "" Or ActiveSheet.Range("L83") = "" Then
jueves = "jueves, "
'MsgBox ("Falta seleccionar menu del Jueves")
End If
End If
'Viernes
If ActiveSheet.Range("J70") = "SI" Then
If ActiveSheet.Range("M83") = "" Or ActiveSheet.Range("N83") = "" Then
viernes = "viernes, "
'MsgBox ("Falta seleccionar menu del Viernes")
End If
End If
If lunes = "lunes, " Or martes = "martes, " Or miercoles = "miercoles, " Or jueves = "jueves, " Or viernes = "viernes, " Then
'Alerta de los dias no completados
MsgBox ("Falta seleccionar menu ó postre del día: " + lunes + martes + miercoles + jueves + viernes)
'If a = vbNo Then Cancel = True
VerificarPedido = False
Exit Function
End If
VerificarPedido = True
End Function

1 Respuesta

Respuesta
2

La macro para el evento de thisworkbook

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Por.Dante Amor
    If SaveAsUI Or boton = False Then
        MsgBox "Solamente puedes guardar presionando el botón de Guardar ", vbExclamation
        Cancel = True
        Exit Sub
    End If
    boton = False
'Fin.Por.Dante Amor
    'If ActiveSheet.Range("H18") = "Ingrese Legajo primero" Then
    'MsgBox ("Por favor ingrese o verifique el numero de legajo")
    'Range("E18").Select
    'Else
    'Lunes
    'If ActiveSheet.Range("J22") = "SI" Then
    'If ActiveSheet.Range("E83") = "" Or ActiveSheet.Range("F83") = "" Then
    'lunes = "lunes, "
    'MsgBox ("Falta seleccionar menu del Lunes")
    'End If
    'End If
    'Martes
    'If ActiveSheet.Range("J34") = "SI" Then
    'If ActiveSheet.Range("G83") = "" Or ActiveSheet.Range("H83") = "" Then
    'martes = "martes, "
    'MsgBox ("Falta seleccionar menu del Martes")
    'End If
    'End If
    'Miercoles
    'If ActiveSheet.Range("J46") = "SI" Then
    'If ActiveSheet.Range("I83") = "" Or ActiveSheet.Range("J83") = "" Then
    'miercoles = "miercoles, "
    'MsgBox ("Falta seleccionar menu del Miercoles")
    ' End If
    ' End If
    'Jueves
    'If ActiveSheet.Range("J58") = "SI" Then
    'If ActiveSheet.Range("K83") = "" Or ActiveSheet.Range("L83") = "" Then
    'jueves = "jueves, "
    'MsgBox ("Falta seleccionar menu del Jueves")
    'End If
    'End If
    'Viernes
    'If ActiveSheet.Range("J70") = "SI" Then
    'If ActiveSheet.Range("M83") = "" Or ActiveSheet.Range("N83") = "" Then
    'viernes = "viernes, "
    'MsgBox ("Falta seleccionar menu del Viernes")
    'End If
    'End If
    'If lunes = "lunes, " Or martes = "martes, " Or miercoles = "miercoles, " Or jueves = "jueves, " Or viernes = "viernes, " Then
    'Alerta de los dias no completados
    'MsgBox ("Falta seleccionar menu ó postre del día: " + lunes + martes + miercoles + jueves + viernes)
    'If a = vbNo Then Cancel = True
    'End If
    'MsgBox ("La celda e6 NO es NUll")
    'End If
End Sub

Las macros para el módulo:

Public boton
'
Sub GuardarCopia()
    'Por.Dante Amor
    If ActiveSheet.Range("H18") = "Ingrese Legajo primero" Then
        MsgBox ("Por favor ingrese o verifique el numero de legajo")
        Range("E18").Select
        Exit Sub
    End If
    Dim verif As Boolean
    verif = VerificarPedido()
    If verif = False Then
        Exit Sub
    Else
        ruta = ThisWorkbook.Path & "\"
        Set h1 = Sheets("menu")
        celda = "H18"
        '
        boton = True
        nombre = h1.Range(celda) & "_" & h1.Range("C18") & ".xlsm"
        ThisWorkbook.SaveCopyAs ruta & nombre
        MsgBox "Copia guardada en " & ruta + nombre, vbInformation, ""
        Application.ActiveWorkbook.Save
        Application.ActiveWorkbook.Close
    End If
End Sub
'
Function VerificarPedido() As Boolean
    '
    'Lunes
    If ActiveSheet.Range("J22") = "SI" Then
    If ActiveSheet.Range("E83") = "" Or ActiveSheet.Range("F83") = "" Then
    lunes = "lunes, "
    'MsgBox ("Falta seleccionar menu del Lunes")
    End If
    End If
    'Martes
    If ActiveSheet.Range("J34") = "SI" Then
    If ActiveSheet.Range("G83") = "" Or ActiveSheet.Range("H83") = "" Then
    martes = "martes, "
    'MsgBox ("Falta seleccionar menu del Martes")
    End If
    End If
    'Miercoles
    If ActiveSheet.Range("J46") = "SI" Then
    If ActiveSheet.Range("I83") = "" Or ActiveSheet.Range("J83") = "" Then
    miercoles = "miercoles, "
    'MsgBox ("Falta seleccionar menu del Miercoles")
    End If
    End If
    'Jueves
    If ActiveSheet.Range("J58") = "SI" Then
    If ActiveSheet.Range("K83") = "" Or ActiveSheet.Range("L83") = "" Then
    jueves = "jueves, "
    'MsgBox ("Falta seleccionar menu del Jueves")
    End If
    End If
    'Viernes
    If ActiveSheet.Range("J70") = "SI" Then
    If ActiveSheet.Range("M83") = "" Or ActiveSheet.Range("N83") = "" Then
    viernes = "viernes, "
    'MsgBox ("Falta seleccionar menu del Viernes")
    End If
    End If
    If lunes = "lunes, " Or martes = "martes, " Or miercoles = "miercoles, " Or jueves = "jueves, " Or viernes = "viernes, " Then
    'Alerta de los dias no completados
    MsgBox ("Falta seleccionar menu ó postre del día: " + lunes + martes + miercoles + jueves + viernes)
    'If a = vbNo Then Cancel = True
    VerificarPedido = False
    Exit Function
    End If
    VerificarPedido = True
End Function

.

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

.

Avísame cualquier duda

.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas