Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

XLA ouvert

3 réponses
Avatar
Patrick
Bonjour,

En VBA, comment puis-je savoir si un fichier ".xla" est déjà ouvert ?

Merci pour votre aide.

--
Patrick

3 réponses

Avatar
LSteph
Bonjour,

Dans Visual Basic Editor ce qui est ouvert

est normalement sur ta gauche, dans l'explorateur de projet.

En VBA tu peux récupèrer les nom correspondants

'selon leur dll

Sub listOdll()
Dim i As Byte, msg As String
With Application.VBE.VBProjects
For i = 1 To .Count
msg = msg & .Item(i).BuildFileName & vbCrLf
Next
End With
MsgBox msg
End Sub

'ou leur nom VBA, pas celui qui est entre parenthèse

Sub listOp()
Dim i As Byte, msg As String
With Application.VBE.VBProjects
For i = 1 To .Count
msg = msg & .Item(i).Name & vbCrLf
Next
End With
MsgBox msg
End Sub

'note que tu aura aussi les .xls

'Cordialement.
'__
'lSteph
Avatar
Frédéric Sigonneau
Un fichier xla est, depuis Excel 97, un classeur comme un autre. S'il est
ouvert, il fait partie des items de la collection Workbooks.
Ce genre de code (solution parmi d'autres) permet de savoir si c'est le cas ou non :

'================= Sub test()
Dim Nom As String
Nom = "BoPliablev2.xla"
MsgBox IsOuvert(Nom)
End Sub

Function IsOuvert(NomXla)
Dim Xla As Workbook
On Error Resume Next
Set Xla = Workbooks(NomXla)
On Error GoTo 0
IsOuvert = Not (Xla Is Nothing)
End Function
'=================
FS
---
Frédéric Sigonneau
http://frederic.sigonneau.free.fr

Bonjour,

En VBA, comment puis-je savoir si un fichier ".xla" est déjà ouvert ?

Merci pour votre aide.



Avatar
Patrick
Merci.

--
Patrick


"Frédéric Sigonneau" wrote:

Un fichier xla est, depuis Excel 97, un classeur comme un autre. S'il est
ouvert, il fait partie des items de la collection Workbooks.
Ce genre de code (solution parmi d'autres) permet de savoir si c'est le cas ou non :

'================= > Sub test()
Dim Nom As String
Nom = "BoPliablev2.xla"
MsgBox IsOuvert(Nom)
End Sub

Function IsOuvert(NomXla)
Dim Xla As Workbook
On Error Resume Next
Set Xla = Workbooks(NomXla)
On Error GoTo 0
IsOuvert = Not (Xla Is Nothing)
End Function
'================= >
FS
---
Frédéric Sigonneau
http://frederic.sigonneau.free.fr

Bonjour,

En VBA, comment puis-je savoir si un fichier ".xla" est déjà ouvert ?

Merci pour votre aide.