Error trying to close the .iam

Error trying to close the .iam

jcorrero87
Enthusiast Enthusiast
316 Views
3 Replies
Message 1 of 4

Error trying to close the .iam

jcorrero87
Enthusiast
Enthusiast

Hello everyone,
Creating a macro to close the set if a password is not introduced. A problem arose when executing "Thisapplication.document.closeall", error 438 arises. Can anyone tell me that I am doing wrong?.
The macro is as follows:

 

Public Sub Doc_c()

If Date <= DateSerial(2022, 11, 20) Then GoTo fin

On Error GoTo Ver_Error

licenciauso = InputBox("Enter the usage password")
If licenciauso <> "password" Then
MsgBox "Incorrect password"
ThisApplication.Document.CloseAll
End If

GoTo fin

Ver_Error:
ThisApplication.Document.CloseAll

fin:

End Sub

 

Thank you so much.

0 Likes
Accepted solutions (2)
317 Views
3 Replies
Replies (3)
Message 2 of 4

ciaran.gibson
Contributor
Contributor
Accepted solution

Error 438 typically occurs when you try to access an object or property that does not exist or is not valid. In this case, it's possible that the issue is caused by the use of ThisApplication.Document.CloseAll.

 
try this:
 
 

Public Sub Doc_c()

' Check if the current date is on or before November 20, 2022
If Date <= DateSerial(2022, 11, 20) Then GoTo fin

' If an error occurs, jump to the Ver_Error section
On Error GoTo Ver_Error

' Prompt the user to enter the usage password
licenciauso = InputBox("Enter the usage password")

' If the password is incorrect, show an error message and close all open documents
If licenciauso <> "password" Then
MsgBox "Incorrect password"
Application.Documents.CloseAll
Exit Sub ' Exit the subroutine to prevent further execution
End If

fin:
' This is the end of the subroutine

End Sub

0 Likes
Message 3 of 4

Michael.Navara
Advisor
Advisor
Accepted solution

Perhaps it is a typo at line

ThisApplication.Document.CloseAll

it should be

ThisApplication.Documents.CloseAll

0 Likes
Message 4 of 4

jcorrero87
Enthusiast
Enthusiast
Thank you very much for the help
0 Likes