checoturco
Registered User.
- Local time
- Yesterday, 21:09
- Joined
- Oct 17, 2005
- Messages
- 76
Hi all,
i have a macro to delete a file first and then the folder that has this file.
What happens it's when i run the macro the first time it works fine, the second time it gives me the error Path/File Access error on the line to remove the folder. if i run again( 3ª time) it works fine again.
this is the code:
Sub Unzip()
Dim oApp As Object
Dim fname
Dim FileNameFolder
fname = Application.GetOpenFilename(filefilter:="Zip Files (*.zip), *.zip", _
MultiSelect:=False)
If fname = False Then
'do nothing
Else
DefPath = "C:\...\desktop\importardate\"
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If
ChDrive "C"
ChDir DefPath
'MsgBox "Active station and folder name: " & CurDir
If Dir(DefPath & "UnzipFolder\xpto.xls") <> "" Then
Kill DefPath & "UnzipFolder\xpto.xls"
End If
FileNameFolder = DefPath & "UnzipFolder"
RmDir FileNameFolder
MkDir FileNameFolder
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(fname).items
Set oApp = Nothing
End If
End Sub
alawys in the second atempt it gives the error.
tks in advance
checoturco
i have a macro to delete a file first and then the folder that has this file.
What happens it's when i run the macro the first time it works fine, the second time it gives me the error Path/File Access error on the line to remove the folder. if i run again( 3ª time) it works fine again.
this is the code:
Sub Unzip()
Dim oApp As Object
Dim fname
Dim FileNameFolder
fname = Application.GetOpenFilename(filefilter:="Zip Files (*.zip), *.zip", _
MultiSelect:=False)
If fname = False Then
'do nothing
Else
DefPath = "C:\...\desktop\importardate\"
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If
ChDrive "C"
ChDir DefPath
'MsgBox "Active station and folder name: " & CurDir
If Dir(DefPath & "UnzipFolder\xpto.xls") <> "" Then
Kill DefPath & "UnzipFolder\xpto.xls"
End If
FileNameFolder = DefPath & "UnzipFolder"
RmDir FileNameFolder
MkDir FileNameFolder
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(fname).items
Set oApp = Nothing
End If
End Sub
alawys in the second atempt it gives the error.
tks in advance
checoturco