+ Reply to Thread
Results 1 to 1 of 1

Scripting.FileSystemObject gives Permission denied

Hybrid View

  1. #1
    Registered User
    Join Date
    03-31-2009
    Location
    Auburn Alabama
    MS-Off Ver
    Microsoft Office Excel 2007 (Windows)
    Posts
    99

    Scripting.FileSystemObject gives Permission denied

    Hello,

    Can someone tell me why I'm getting the error message "run-time error '70' Permission denied" when running the code below?

    The code below involves 2 sub-procedures which are being used to list folders on my computer.

    I'm running Vista Home Edition. I was under the impression that if I clicked the Windows icon and typed 'Excel' into the start search prompt, that by then pressing CTRL + SHIFT + Enter I would start Excel as Admin and not be denied permission to folders and files.

    As shown below, the first sub executes and calls the second sub which throws an error at the line "Cells(r, 3).Value = SourceFolder.Size". The debugger then shows "SourceFolder.Size = <Permission denied>".

    Thanks for any and all advice in advance! Your help is greatly appreciated!

    Sub CreateList()
        Application.ScreenUpdating = False
        Workbooks.Add    ' create a new workbook for the folder list
        ' add headers
        With Cells(1, 1)
            .Value = "Folder contents:"
            .Font.Bold = True
            .Font.Size = 12
        End With
        Cells(3, 1).Value = "Folder Path:"
        Cells(3, 2).Value = "Folder Name:"
        Cells(3, 3).Value = "Size:"
        Cells(3, 4).Value = "Subfolders:"
        Cells(3, 5).Value = "Files:"
        Cells(3, 6).Value = "Short Name:"
        Cells(3, 7).Value = "Short Path:"
        Range("A3:G3").Font.Bold = True
        ListFolders BrowseFolder, True
        Application.ScreenUpdating = True
    Sub ListFolders(SourceFolderName As String, IncludeSubfolders As Boolean)
        ' lists information about the folders in SourceFolder
        Dim FSO    As Scripting.FileSystemObject
        Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
        Dim r      As Long
        Set FSO = New Scripting.FileSystemObject
        Set SourceFolder = FSO.GetFolder(SourceFolderName)
        ' display folder properties
        r = Cells(Rows.Count, 1).End(xlUp).Row + 1
        Cells(r, 1).Value = SourceFolder.Path
        Cells(r, 2).Value = SourceFolder.Name
        Cells(r, 3).Value = SourceFolder.Size
        Cells(r, 4).Value = SourceFolder.SubFolders.Count
        Cells(r, 5).Value = SourceFolder.Files.Count
        Cells(r, 6).Value = SourceFolder.ShortName
        Cells(r, 7).Value = SourceFolder.ShortPath
        If IncludeSubfolders Then
            For Each SubFolder In SourceFolder.SubFolders
                ListFolders SubFolder.Path, True
            Next SubFolder
            Set SubFolder = Nothing
        End If
        Columns("A:G").AutoFit
        Set SourceFolder = Nothing
        Set FSO = Nothing
        ActiveWorkbook.Saved = True
    End Sub
    Last edited by CrazyFileMaker; 03-16-2011 at 02:33 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1