Dim ThisOne(1 To 50) As String
With Application.FileSearch
.LookIn = "C:\ Mes Documents\TheObject.xls"
.FileType = msoFileTypeExcelWorkbooks
.Execute
End With
If Application.FileSearch.FoundFiles.Count >= 1 Then
For x = 1 To Application.FileSearch.FoundFiles.Count
ThisOne(x) = Application.FileSearch.FoundFiles.Item(x)
If ThisOne(x) = "C:\Mes Documents\TheObject.xls" Then
<<< suppression du fichier >>>
Comment supprimer le fichier?
"Delete" me retourne toujours la mention objet requis.
est-ce un Pb de syntaxe ?
Merci d'avance pour vos contributions !
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
Clément Marcotte
Bonjour,
Kill "nom du fichier"
Mais le fichier ne va pas dans la corbeille...
"sébastien" a écrit dans le message de news:0e4c01c3a3b3$8db35700$
Bonjour,
voici le PB :
Dim ThisOne(1 To 50) As String With Application.FileSearch .LookIn = "C: Mes DocumentsTheObject.xls" .FileType = msoFileTypeExcelWorkbooks .Execute End With If Application.FileSearch.FoundFiles.Count >= 1 Then For x = 1 To Application.FileSearch.FoundFiles.Count ThisOne(x) = Application.FileSearch.FoundFiles.Item(x) If ThisOne(x) = "C:Mes DocumentsTheObject.xls" Then <<< suppression du fichier >>>
Comment supprimer le fichier? "Delete" me retourne toujours la mention objet requis. est-ce un Pb de syntaxe ? Merci d'avance pour vos contributions !
Bonjour,
Kill "nom du fichier"
Mais le fichier ne va pas dans la corbeille...
"sébastien" <sebasoleines@fre.fr> a écrit dans le message de
news:0e4c01c3a3b3$8db35700$a601280a@phx.gbl...
Bonjour,
voici le PB :
Dim ThisOne(1 To 50) As String
With Application.FileSearch
.LookIn = "C: Mes DocumentsTheObject.xls"
.FileType = msoFileTypeExcelWorkbooks
.Execute
End With
If Application.FileSearch.FoundFiles.Count >= 1 Then
For x = 1 To Application.FileSearch.FoundFiles.Count
ThisOne(x) = Application.FileSearch.FoundFiles.Item(x)
If ThisOne(x) = "C:Mes DocumentsTheObject.xls" Then
<<< suppression du fichier >>>
Comment supprimer le fichier?
"Delete" me retourne toujours la mention objet requis.
est-ce un Pb de syntaxe ?
Merci d'avance pour vos contributions !
"sébastien" a écrit dans le message de news:0e4c01c3a3b3$8db35700$
Bonjour,
voici le PB :
Dim ThisOne(1 To 50) As String With Application.FileSearch .LookIn = "C: Mes DocumentsTheObject.xls" .FileType = msoFileTypeExcelWorkbooks .Execute End With If Application.FileSearch.FoundFiles.Count >= 1 Then For x = 1 To Application.FileSearch.FoundFiles.Count ThisOne(x) = Application.FileSearch.FoundFiles.Item(x) If ThisOne(x) = "C:Mes DocumentsTheObject.xls" Then <<< suppression du fichier >>>
Comment supprimer le fichier? "Delete" me retourne toujours la mention objet requis. est-ce un Pb de syntaxe ? Merci d'avance pour vos contributions !
Denis Michon
Bonjour Sébastien,
D'autres alternatives en plus de celle proposé par Clément Marcotte.
Une façon qu'à déjà soumise Frédéric Sigonneau pour envoyer directement le fichier supprimé à la poubelle :
'Déclaration dans le haut d'un module : API Declare Function SHFileOperation Lib "shell32.dll" Alias _ "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Type SHFILEOPSTRUCT hwnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAnyOperationsAborted As Boolean hNameMappings As Long lpszProgressTitle As String End Type
Sub test() 'à adapter RecycleFile "D:fsdatas 6OfficeVBA 0ExemplesEtTestsExemplesClasseur1.xls" End Sub
Sub RecycleFile(sFile As String) 'Chip Pearson, mpep Const FO_DELETE = &H3 Const FOF_ALLOWUNDO = &H40 'décommenter si la demande de confirmation n'est pas nécessaire 'Const FOF_NOCONFIRMATION = &H10
Dim FileOperation As SHFILEOPSTRUCT Dim lReturn As Long Dim sFileName As String
With FileOperation .wFunc = FO_DELETE .pFrom = sFile .fFlags = FOF_ALLOWUNDO '+ FOF_NOCONFIRMATION 'idem End With lReturn = SHFileOperation(FileOperation) End Sub '======================
Et si tu veux utiliser le FileScriptingObject : Sans passer par la poubelle !
'---------------------------- Sub SupprimerFichier()
Dim fs As Object, Fichier As String
Fichier = "C:excelclass1.xls" 'à déterminer
Set fs = CreateObject("Scripting.FileSystemObject")
If Dir(Fichier) <> "" Then Set F = fs.getfile(Fichier) F.Delete Else MsgBox "Fichier introuvable." End If
Set fs = Nothing: Set F = Nothing
End Sub '----------------------------
Salutations!
"sébastien" a écrit dans le message de news:0e4c01c3a3b3$8db35700$ Bonjour,
voici le PB :
Dim ThisOne(1 To 50) As String With Application.FileSearch .LookIn = "C: Mes DocumentsTheObject.xls" .FileType = msoFileTypeExcelWorkbooks .Execute End With If Application.FileSearch.FoundFiles.Count >= 1 Then For x = 1 To Application.FileSearch.FoundFiles.Count ThisOne(x) = Application.FileSearch.FoundFiles.Item(x) If ThisOne(x) = "C:Mes DocumentsTheObject.xls" Then <<< suppression du fichier >>>
Comment supprimer le fichier? "Delete" me retourne toujours la mention objet requis. est-ce un Pb de syntaxe ? Merci d'avance pour vos contributions !
Bonjour Sébastien,
D'autres alternatives en plus de celle proposé par Clément Marcotte.
Une façon qu'à déjà soumise Frédéric Sigonneau pour envoyer directement le fichier supprimé à la poubelle :
'Déclaration dans le haut d'un module : API
Declare Function SHFileOperation Lib "shell32.dll" Alias _
"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type
Sub test()
'à adapter
RecycleFile "D:fsdatas 6OfficeVBA 0ExemplesEtTestsExemplesClasseur1.xls"
End Sub
Sub RecycleFile(sFile As String)
'Chip Pearson, mpep
Const FO_DELETE = &H3
Const FOF_ALLOWUNDO = &H40
'décommenter si la demande de confirmation n'est pas nécessaire
'Const FOF_NOCONFIRMATION = &H10
Dim FileOperation As SHFILEOPSTRUCT
Dim lReturn As Long
Dim sFileName As String
With FileOperation
.wFunc = FO_DELETE
.pFrom = sFile
.fFlags = FOF_ALLOWUNDO '+ FOF_NOCONFIRMATION 'idem
End With
lReturn = SHFileOperation(FileOperation)
End Sub
'======================
Et si tu veux utiliser le FileScriptingObject : Sans passer par la poubelle !
'----------------------------
Sub SupprimerFichier()
Dim fs As Object, Fichier As String
Fichier = "C:excelclass1.xls" 'à déterminer
Set fs = CreateObject("Scripting.FileSystemObject")
If Dir(Fichier) <> "" Then
Set F = fs.getfile(Fichier)
F.Delete
Else
MsgBox "Fichier introuvable."
End If
Set fs = Nothing: Set F = Nothing
End Sub
'----------------------------
Salutations!
"sébastien" <sebasoleines@fre.fr> a écrit dans le message de news:0e4c01c3a3b3$8db35700$a601280a@phx.gbl...
Bonjour,
voici le PB :
Dim ThisOne(1 To 50) As String
With Application.FileSearch
.LookIn = "C: Mes DocumentsTheObject.xls"
.FileType = msoFileTypeExcelWorkbooks
.Execute
End With
If Application.FileSearch.FoundFiles.Count >= 1 Then
For x = 1 To Application.FileSearch.FoundFiles.Count
ThisOne(x) = Application.FileSearch.FoundFiles.Item(x)
If ThisOne(x) = "C:Mes DocumentsTheObject.xls" Then
<<< suppression du fichier >>>
Comment supprimer le fichier?
"Delete" me retourne toujours la mention objet requis.
est-ce un Pb de syntaxe ?
Merci d'avance pour vos contributions !
D'autres alternatives en plus de celle proposé par Clément Marcotte.
Une façon qu'à déjà soumise Frédéric Sigonneau pour envoyer directement le fichier supprimé à la poubelle :
'Déclaration dans le haut d'un module : API Declare Function SHFileOperation Lib "shell32.dll" Alias _ "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Type SHFILEOPSTRUCT hwnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAnyOperationsAborted As Boolean hNameMappings As Long lpszProgressTitle As String End Type
Sub test() 'à adapter RecycleFile "D:fsdatas 6OfficeVBA 0ExemplesEtTestsExemplesClasseur1.xls" End Sub
Sub RecycleFile(sFile As String) 'Chip Pearson, mpep Const FO_DELETE = &H3 Const FOF_ALLOWUNDO = &H40 'décommenter si la demande de confirmation n'est pas nécessaire 'Const FOF_NOCONFIRMATION = &H10
Dim FileOperation As SHFILEOPSTRUCT Dim lReturn As Long Dim sFileName As String
With FileOperation .wFunc = FO_DELETE .pFrom = sFile .fFlags = FOF_ALLOWUNDO '+ FOF_NOCONFIRMATION 'idem End With lReturn = SHFileOperation(FileOperation) End Sub '======================
Et si tu veux utiliser le FileScriptingObject : Sans passer par la poubelle !
'---------------------------- Sub SupprimerFichier()
Dim fs As Object, Fichier As String
Fichier = "C:excelclass1.xls" 'à déterminer
Set fs = CreateObject("Scripting.FileSystemObject")
If Dir(Fichier) <> "" Then Set F = fs.getfile(Fichier) F.Delete Else MsgBox "Fichier introuvable." End If
Set fs = Nothing: Set F = Nothing
End Sub '----------------------------
Salutations!
"sébastien" a écrit dans le message de news:0e4c01c3a3b3$8db35700$ Bonjour,
voici le PB :
Dim ThisOne(1 To 50) As String With Application.FileSearch .LookIn = "C: Mes DocumentsTheObject.xls" .FileType = msoFileTypeExcelWorkbooks .Execute End With If Application.FileSearch.FoundFiles.Count >= 1 Then For x = 1 To Application.FileSearch.FoundFiles.Count ThisOne(x) = Application.FileSearch.FoundFiles.Item(x) If ThisOne(x) = "C:Mes DocumentsTheObject.xls" Then <<< suppression du fichier >>>
Comment supprimer le fichier? "Delete" me retourne toujours la mention objet requis. est-ce un Pb de syntaxe ? Merci d'avance pour vos contributions !