View Single Post
 
Old 10-02-2019, 05:10 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Your biggest problem here is that you cannot force users to run your macro and Windows security will conspire against you running that macro by warning users not to run it, however given that, the following macro would delete the content of the document, clear the undo stack and save the document without creating a backup.

Code:
Option Explicit

Sub Document_Open()

Dim FechaCaducidad As Date
Dim bBackup As Boolean
    FechaCaducidad = #4/5/2020#
    If FechaCaducidad > Date Then
        'Mensaje de bienvenida
        MsgBox ("Bienvenid@" + Chr(13) + Chr(10) & "LE SALUDA SU PROFESOR FELIX FALCONI" + Chr(13) + Chr(10))

    Else
        MsgBox "Este archivo dejo de funcionar" & vbCrLf & "Finalizó el período de utilizacion", vbCritical
        Application.DisplayAlerts = False
        DeleteAll
        ActiveDocument.UndoClear
        ActiveDocument.SaveAs ActiveDocument.FullName
    End If
End Sub

Sub DeleteAll()
Dim oStory As Range
    For Each oStory In ActiveDocument.StoryRanges
        If oStory.StoryType = wdMainTextStory Then
            oStory.Text = "Este archivo dejo de funcionar" & vbCrLf & "Finalizó el período de utilizacion"
            oStory.Font.Size = 30
        Else
            oStory.Text = ""
        End If
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                oStory.Text = ""
            Wend
        End If
    Next oStory
    Set oStory = Nothing
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote