Bonjour,
J'ai une macro qui liste les différents fichiers d'un dossier ainsi que
leurs propriétés et je voudrais rajouter la mention "ouverture avec mot
de passe" si c'est le cas.
Je n'ai pas besoin de connaître le mot de passe, juste de savoir qu'il y
en a un soit à l'ouverture soit en édition.
Je ne trouve pas cette information dans les propriétés du fichier.
Pour ceux que ça intéresse, la macro ci-dessous permet de vérifier la protection d'un document en testant, comme indiqué par Jacques, l'existence du dossier "Thumbnails" dans le document (zip).
8< ----------------------------------------------------------------
Function IsDocumentProtected(ByRef pDocURL As String) As Integer
'Checks whether a given LibreOffice document is protected
'This test is based upon the fact that a LibO protected document zip structure
'doesn't contain the usual 'Thumbnails' directory.
'
'Input:
'-- pDocURL: the document name (FQDN) in URL form.
' This document is supposed to exist.
'Output: 1 if the document is protected in any way, 0 if the document is not protected
' or -1 if an error occurred (eg: the document is not a LibO one/not in zip format)
Const ZIP_DIR_ROOT = ""
Const ZIP_DIR_THUMBNAILS = "Thumbnails"
Dim l_Protected As Integer
Dim lo_Package As Object 'the zip document container
Dim l_Arg As New com.sun.star.beans.NamedValue
l_Protected = -1 'default value: unknown/error
On Local Error Goto ErrHandler
lo_Package = createUnoService("com.sun.star.packages.Package")
'open the document zip container
l_Arg.Name = "PackageFormat"
l_Arg.Value = False 'plain Zip format
lo_Package.initialize(Array(pDocURL), l_Arg)
'check for "Thumbnails" directory
'Checking for root first allows to ignore non-zip containers
If lo_Package.hasByHierarchicalName(ZIP_DIR_ROOT) Then
If lo_Package.hasByHierarchicalName(ZIP_DIR_THUMBNAILS) Then
l_Protected = 0 'not protected
Else
l_Protected = 1 'protected
End If
End If
'close zip container
lo_Package = Nothing
ErrHandler:
'do nothing
'We get here either because everything went OK or because the .initialize went wrong.
IsDocumentProtected = l_Protected
End Function 'IsDocumentProtected
---------------------------------------------------------------- >8
Pour l'appeler, voici un bout de code :
8< ----------------------------------------------------------------
Sub Test()
Dim l_FileName As String
Dim l_ThisDir As String
l_ThisDir = "C:/Chemin/Vers/"
l_FileName = ConvertToURL(l_ThisDir & "MonFichier.ods")
Select Case IsDocumentProtected(l_FileName)
Case 0
MsgBox l_FileName & " NON protégé"
Case 1
MsgBox l_FileName & " protégé"
Case -1
MsgBox l_FileName & " INCONNU"
End Select
End Sub 'Test
---------------------------------------------------------------- >8
Si vous répondez, merci de penser à utiliser la fonction "répondre à tous" de votre logiciel de courrier électronique de façon que la liste reçoive une copie de votre réponse.
Bien cordialement,