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

Tester si un document word est ouvert

3 réponses
Avatar
seb.....
Bonjour,

Comment fait on pour tester si un document word spécifique est ouvert ?

merci

seb

3 réponses

Avatar
Thierry (ze Titi)
Bonjour !

seb..... avait écrit le 12/12/2007 :
Comment fait on pour tester si un document word spécifique est ouvert ?
A copier dans un module:


Function IsFileOpen(filename As String) As Boolean
Dim filenum As Integer, Errnum As Integer
On Error Resume Next
filenum = FreeFile()
Open filename For Input Lock Read As #filenum
Close filenum
Errnum = Err
On Error GoTo 0
Select Case Errnum
Case 0
IsFileOpen = False
Case 70
IsFileOpen = True
End Select
End Function

Le test se fait de la façon suivante:

If IsFileOpen("c:lefichier.doc") Then
MsgBox "Fichier ouvert"
Else
MsgBox "Fichier non ouvert"
End If

Dis-nous !

--
Cordialement,
Thierry

tout pour Access :
http://www.mpfa.info

Avatar
Eric
Re,

Via les APIs pour n'importe quel fichier:

Option Compare Database
Option Explicit

'Determine whether a file is already open or not
Private Declare Function lOpen Lib "kernel32" Alias "_lopen" _
(ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function lClose Lib "kernel32" Alias "_lclose" _
(ByVal hFile As Long) As Long
Private Function IsFileAlreadyOpen(FileName As String) As Boolean
Dim hFile As Long
Dim lastErr As Long
' Initialize file handle and error variable.
hFile = -1
lastErr = 0
' Open for for read and exclusive sharing.
hFile = lOpen(FileName, &H10)
' If we couldn't open the file, get the last error.
If hFile = -1 Then
lastErr = Err.LastDllError
Else
' Make sure we close the file on success.
lClose (hFile)
End If
' Check for sharing violation error.
IsFileAlreadyOpen = (hFile = -1) And (lastErr = 32)
End Function


Utilisation :

Sub zz()
MsgBox IsFileAlreadyOpen("c:doc1.doc")
End Sub

Bonjour,

Comment fait on pour tester si un document word spécifique est ouvert ?

merci

seb




--
A+
Eric
http://www.mpfa.info/
Archives : http://groups.google.fr/group/microsoft.public.fr.access?hl=fr

Avatar
seb.....
Merci à tous les deux.

Cela fonctionne nikel

"seb....." (paslamarque).fr> a écrit dans le message de news:
fjovke$lue$
Bonjour,

Comment fait on pour tester si un document word spécifique est ouvert ?

merci

seb