dhananjay
01-07-2009, 07:39 AM
I am trying to delete a readonly folder using vba...
Dim MyDodgyFolder
MyDodgyFolder = "C:\MyPath\MyFolderName"
SetAttr MyDodgyFolder, VBNormal
This did not work...
So tried this, with type mismatch error..
Dim oFSO As New FileSystemObject
Dim oFolder As folder, oFile As File
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\zimmer\test\" & packFold)
'packFold is the variable with folder name. This folder is present in location
' this line gives the error
For Each oFile In oFolder
fileAtt = VBA.GetAttr(oFile.Path)
If fileAtt And vbReadOnly Then
Call VBA.SetAttr(oFile.Path, fileAtt - vbReadOnly)
End If
Next
oFSO.DeleteFolder "C:\zimmer\test\" & packFold
Dim MyDodgyFolder
MyDodgyFolder = "C:\MyPath\MyFolderName"
SetAttr MyDodgyFolder, VBNormal
This did not work...
So tried this, with type mismatch error..
Dim oFSO As New FileSystemObject
Dim oFolder As folder, oFile As File
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\zimmer\test\" & packFold)
'packFold is the variable with folder name. This folder is present in location
' this line gives the error
For Each oFile In oFolder
fileAtt = VBA.GetAttr(oFile.Path)
If fileAtt And vbReadOnly Then
Call VBA.SetAttr(oFile.Path, fileAtt - vbReadOnly)
End If
Next
oFSO.DeleteFolder "C:\zimmer\test\" & packFold