Depuis une feuille de calcul, en cliquant sur un bouton j'aimerais modifier
une propriété personnalisée "Version" d'un fichier Excel fermé situé sur
C:\Test.xls.
La propriété personnalisée Version à pour type Numéro.
Il faut incrémenter de 1 la valeur initiale la propriété personnalisée
"Version".
Exemples :
* si Version = 1 -> mettre 2
* si Version = 10 -> mettre 11
Je pense qu'il faut utiliser "CustomDocumentProperties" mais je ne maîtrise
pas le code. Est-il possible de réaliser cette opération sans ouvrir le
fichier C:\Test.xls ?
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
anonymousA
bonjour,
n'ai pas testé mais parait répondre à ta question. si tu n'a pas la bibiothèque spécifiée, voir ci-dessous
Document Properties Of Closed Files
There is a library of procedures available that allows you to read (and, in some cases, write) properties of closed files. Moreover, you can read properties of any OLE Structured Storage file, such as Word documents, PowerPoint presentations, and so on. Your code will need a reference to the "DS: OLE Document Properties 1.2 Object Library" . Go to the Tools menu, choose References, and select this library. If you do not have this library installed, you can download it for free from Microsoft at http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q224351 .
'Lire et écrire les propriétés personnalisées d'un document 'En ajouter et en supprimer. 'Notes : '- La bibliothèque : 'DS: OLE Document Properties 1.4 Object Library 'doit être cochée dans OutilsRéférences '- Les fichiers manipulés doivent être *fermés*
Public Const Fich$ = "D:CalculsEuros.xls" 'par exemple Public Const Prop$ = "Version1"
Sub TestEcriture() WriteCustomProp Prop End Sub
Sub TestLecture() ReadAllProps ReadCustomPropValue Prop End Sub
Sub TestSupprProp() DeleteCustomProp Prop End Sub
Sub WriteCustomProp(NomProp) Dim DSO As DSOleFile.PropertyReader Dim LesProps As DSOleFile.DocumentProperties
Set DSO = New DSOleFile.PropertyReader Set LesProps = DSO.GetDocumentProperties(Fich) LesProps.CustomProperties.Add NomProp, Now
End Sub
Sub ReadCustomPropValue(NomProp) Dim DSO As DSOleFile.PropertyReader Dim LesProps As DSOleFile.DocumentProperties
Set DSO = New DSOleFile.PropertyReader Set LesProps = DSO.GetDocumentProperties(Fich) MsgBox LesProps.CustomProperties(NomProp).Value
End Sub
Sub ReadAllProps() Dim DSO As DSOleFile.PropertyReader Dim LesProps As DSOleFile.DocumentProperties Dim i&, Msg$
Set DSO = New DSOleFile.PropertyReader Set LesProps = DSO.GetDocumentProperties(Fich) For i = 1 To LesProps.CustomProperties.Count Msg = Msg & LesProps.CustomProperties(i).Name & _ " " & LesProps.CustomProperties(i).Value & vbLf Next MsgBox Msg
End Sub
Sub DeleteCustomProp(NomProp) Dim DSO As DSOleFile.PropertyReader Dim LesProps As DSOleFile.DocumentProperties
Set DSO = New DSOleFile.PropertyReader Set LesProps = DSO.GetDocumentProperties(Fich) LesProps.CustomProperties(NomProp).Remove
End Sub
A+
bonjour,
n'ai pas testé mais parait répondre à ta question. si tu n'a pas la
bibiothèque spécifiée, voir ci-dessous
Document Properties Of Closed Files
There is a library of procedures available that allows you to read
(and, in some cases, write) properties of closed files. Moreover, you
can read properties of any OLE Structured Storage file, such as Word
documents, PowerPoint presentations, and so on. Your code will need a
reference to the "DS: OLE Document Properties 1.2 Object Library" . Go
to the Tools menu, choose References, and select this library. If you
do not have this library installed, you can download it for free from
Microsoft at
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q224351 .
'Lire et écrire les propriétés personnalisées d'un document
'En ajouter et en supprimer.
'Notes :
'- La bibliothèque :
'DS: OLE Document Properties 1.4 Object Library
'doit être cochée dans OutilsRéférences
'- Les fichiers manipulés doivent être *fermés*
Public Const Fich$ = "D:CalculsEuros.xls" 'par exemple
Public Const Prop$ = "Version1"
Sub TestEcriture()
WriteCustomProp Prop
End Sub
Sub TestLecture()
ReadAllProps
ReadCustomPropValue Prop
End Sub
Sub TestSupprProp()
DeleteCustomProp Prop
End Sub
Sub WriteCustomProp(NomProp)
Dim DSO As DSOleFile.PropertyReader
Dim LesProps As DSOleFile.DocumentProperties
Set DSO = New DSOleFile.PropertyReader
Set LesProps = DSO.GetDocumentProperties(Fich)
LesProps.CustomProperties.Add NomProp, Now
End Sub
Sub ReadCustomPropValue(NomProp)
Dim DSO As DSOleFile.PropertyReader
Dim LesProps As DSOleFile.DocumentProperties
Set DSO = New DSOleFile.PropertyReader
Set LesProps = DSO.GetDocumentProperties(Fich)
MsgBox LesProps.CustomProperties(NomProp).Value
End Sub
Sub ReadAllProps()
Dim DSO As DSOleFile.PropertyReader
Dim LesProps As DSOleFile.DocumentProperties
Dim i&, Msg$
Set DSO = New DSOleFile.PropertyReader
Set LesProps = DSO.GetDocumentProperties(Fich)
For i = 1 To LesProps.CustomProperties.Count
Msg = Msg & LesProps.CustomProperties(i).Name & _
" " & LesProps.CustomProperties(i).Value & vbLf
Next
MsgBox Msg
End Sub
Sub DeleteCustomProp(NomProp)
Dim DSO As DSOleFile.PropertyReader
Dim LesProps As DSOleFile.DocumentProperties
Set DSO = New DSOleFile.PropertyReader
Set LesProps = DSO.GetDocumentProperties(Fich)
LesProps.CustomProperties(NomProp).Remove
n'ai pas testé mais parait répondre à ta question. si tu n'a pas la bibiothèque spécifiée, voir ci-dessous
Document Properties Of Closed Files
There is a library of procedures available that allows you to read (and, in some cases, write) properties of closed files. Moreover, you can read properties of any OLE Structured Storage file, such as Word documents, PowerPoint presentations, and so on. Your code will need a reference to the "DS: OLE Document Properties 1.2 Object Library" . Go to the Tools menu, choose References, and select this library. If you do not have this library installed, you can download it for free from Microsoft at http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q224351 .
'Lire et écrire les propriétés personnalisées d'un document 'En ajouter et en supprimer. 'Notes : '- La bibliothèque : 'DS: OLE Document Properties 1.4 Object Library 'doit être cochée dans OutilsRéférences '- Les fichiers manipulés doivent être *fermés*
Public Const Fich$ = "D:CalculsEuros.xls" 'par exemple Public Const Prop$ = "Version1"
Sub TestEcriture() WriteCustomProp Prop End Sub
Sub TestLecture() ReadAllProps ReadCustomPropValue Prop End Sub
Sub TestSupprProp() DeleteCustomProp Prop End Sub
Sub WriteCustomProp(NomProp) Dim DSO As DSOleFile.PropertyReader Dim LesProps As DSOleFile.DocumentProperties
Set DSO = New DSOleFile.PropertyReader Set LesProps = DSO.GetDocumentProperties(Fich) LesProps.CustomProperties.Add NomProp, Now
End Sub
Sub ReadCustomPropValue(NomProp) Dim DSO As DSOleFile.PropertyReader Dim LesProps As DSOleFile.DocumentProperties
Set DSO = New DSOleFile.PropertyReader Set LesProps = DSO.GetDocumentProperties(Fich) MsgBox LesProps.CustomProperties(NomProp).Value
End Sub
Sub ReadAllProps() Dim DSO As DSOleFile.PropertyReader Dim LesProps As DSOleFile.DocumentProperties Dim i&, Msg$
Set DSO = New DSOleFile.PropertyReader Set LesProps = DSO.GetDocumentProperties(Fich) For i = 1 To LesProps.CustomProperties.Count Msg = Msg & LesProps.CustomProperties(i).Name & _ " " & LesProps.CustomProperties(i).Value & vbLf Next MsgBox Msg
End Sub
Sub DeleteCustomProp(NomProp) Dim DSO As DSOleFile.PropertyReader Dim LesProps As DSOleFile.DocumentProperties
Set DSO = New DSOleFile.PropertyReader Set LesProps = DSO.GetDocumentProperties(Fich) LesProps.CustomProperties(NomProp).Remove