shadowman_2k3
Nouveau membre
Salut à tous,
J'ai une fonction copier/couper en vba et pour la partie couper, j'ai besoin de tester si le fichier est ouvert.
Voici le code
[cpp]'The function copy_files carries out a copy/cut of a tree structure of files in only one folder, and it sends the number of file it copies/cuts.
'srcfolder is the folder of the source of the tree structure.
'destfolder is the destination's folder.
'subfolders is a boolean who allows the transaction in the sub folders of the source folder.
'suppr is a bolean who is allows the cut of the transaction
Function copy_files(srcFolder As String, destFolder As String, subFolders As Boolean, suppr As Boolean) As Integer
On Error GoTo errHandler
Dim fso As New FileSystemObject
Dim theFile As file
Dim theFiles As Files
Dim theFolder As Folder
Dim theSubFolders As Folders
Set theFolder = fso.GetFolder(srcFolder)
Set theFiles = theFolder.Files
Set theSubFolders = theFolder.subFolders
If theFiles.Count > 0 Then
copy_files = theFiles.Count
For Each theFile In theFiles
If suppr Then
fso.MoveFile theFile, destFolder & "\"
Else
fso.CopyFile theFile, destFolder & "\"
End If
Next
End If
Set theFile = Nothing
Set theFiles = Nothing
Set theFolder = Nothing
Set fso = Nothing
If theSubFolders.Count > 0 And subFolders Then
For Each theFolder In theSubFolders
If suppr Then
copy_files = copy_files + copy_files(theFolder.path, destFolder, True, True)
Else
copy_files = copy_files + copy_files(theFolder.path, destFolder, True, False)
End If
Next
End If
Set theSubFolders = Nothing
Exit Function
If Not Error Then
GoTo fin
End If
errHandler:
copy_files = -err.Number
fin:
End Function
[/cpp]
Donc comment faire pour tester le fichier?
Merci
J'ai une fonction copier/couper en vba et pour la partie couper, j'ai besoin de tester si le fichier est ouvert.
Voici le code
[cpp]'The function copy_files carries out a copy/cut of a tree structure of files in only one folder, and it sends the number of file it copies/cuts.
'srcfolder is the folder of the source of the tree structure.
'destfolder is the destination's folder.
'subfolders is a boolean who allows the transaction in the sub folders of the source folder.
'suppr is a bolean who is allows the cut of the transaction
Function copy_files(srcFolder As String, destFolder As String, subFolders As Boolean, suppr As Boolean) As Integer
On Error GoTo errHandler
Dim fso As New FileSystemObject
Dim theFile As file
Dim theFiles As Files
Dim theFolder As Folder
Dim theSubFolders As Folders
Set theFolder = fso.GetFolder(srcFolder)
Set theFiles = theFolder.Files
Set theSubFolders = theFolder.subFolders
If theFiles.Count > 0 Then
copy_files = theFiles.Count
For Each theFile In theFiles
If suppr Then
fso.MoveFile theFile, destFolder & "\"
Else
fso.CopyFile theFile, destFolder & "\"
End If
Next
End If
Set theFile = Nothing
Set theFiles = Nothing
Set theFolder = Nothing
Set fso = Nothing
If theSubFolders.Count > 0 And subFolders Then
For Each theFolder In theSubFolders
If suppr Then
copy_files = copy_files + copy_files(theFolder.path, destFolder, True, True)
Else
copy_files = copy_files + copy_files(theFolder.path, destFolder, True, False)
End If
Next
End If
Set theSubFolders = Nothing
Exit Function
If Not Error Then
GoTo fin
End If
errHandler:
copy_files = -err.Number
fin:
End Function
[/cpp]
Donc comment faire pour tester le fichier?
Merci