Advertisement
elviscortijo

Borrar antes de Cerrar las Hojas "HOJA" - EXCEL VBA

May 15th, 2020
2,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub Workbook_BeforeClose _
  2.     (Cancel As Boolean)
  3. Dim ws As Worksheet
  4. Dim Resp As Long
  5. Dim ShowCount As Long
  6.  
  7. ShowCount = 0
  8.  
  9. For Each ws In ThisWorkbook.Worksheets
  10.   If UCase(Left(ws.Name, 4)) = "HOJA" Then
  11.     ShowCount = ShowCount + 1
  12.   End If
  13. Next ws
  14.  
  15. If ShowCount > 0 Then
  16.   Resp = MsgBox("Desea Borrar las Hojas de detalle??", _
  17.           vbYesNo, "Borrar Hojas?")
  18.   If Resp = vbYes Then
  19.     Application.DisplayAlerts = False
  20.     For Each ws In ThisWorkbook.Worksheets
  21.       If UCase(Left(ws.Name, 4)) = "HOJA" Then
  22.         ws.Delete
  23.       End If
  24.     Next ws
  25.   End If
  26. End If
  27.  
  28. Set ws = Nothing
  29.  
  30. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement