+ Reply to Thread
Results 1 to 6 of 6

Function for FileLen

Hybrid View

  1. #1
    Registered User
    Join Date
    06-23-2014
    Location
    MidWest, USA
    MS-Off Ver
    2016
    Posts
    89

    Function for FileLen

    Good day,
    Do anyone know if there is a function/formula which can be used to display the total size of a text file? I have a spreadsheet template on a Sharepoint library that checks 8 text files daily and modifies and saves content saved in each. I'd like to have this template screen out empty files so I can use a loop macro and I thought FileLen would be the best way to do that. But I can't get it to work like the function FileExists. Is it possible? Or does it only work through VBA code?
    Last edited by Seth_; 07-19-2019 at 01:03 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,940

    Re: Function for FileLen

    Here is a Macro I have used in the past that you can modify as necessary

    Sub ListAllFile()
    
        Dim objFSO As Object
        Dim objFolder As Object
        Dim objFile As Object
        Dim ws As Worksheet
        Dim sPath As String
        Dim lrA As Long
        Dim lrB As Long
    
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set ws = Worksheets.Add
    
        'Get the folder object associated with the directory
        sPath = InputBox("What is the full Path to Search?")
        Set objFolder = objFSO.GetFolder(sPath)
        ws.Cells(1, 1).Value = "The files found in " & objFolder.Name & " are:"
        ws.Cells(1, 2).Value = "The files found have modified dates:"
        ws.Cells(1, 3).Value = "The file Size is:"
    
        'Loop through the Files collection
        For Each objFile In objFolder.Files
        'If objFile.Name Like "*.pdf" Then
            lrA = Range("A" & Rows.Count).End(xlUp).Row
            lrB = Range("B" & Rows.Count).End(xlUp).Row
            ws.Range("A" & lrA + 1).Value = objFile.Name
            ws.Range("B" & lrB + 1).Value = objFile.DateLastModified
            ws.Range("C" & lrB + 1).Value = objFile.Size
        'End If
        Next
        'ws.Cells(2, 1).Delete
        'Clean up!
        Set objFolder = Nothing
        Set objFile = Nothing
        Set objFSO = Nothing
    
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    06-23-2014
    Location
    MidWest, USA
    MS-Off Ver
    2016
    Posts
    89

    Re: Function for FileLen

    Alan, for the line that reads "sPath = InputBox("What is the full Path to Search?")" did you use a sharepoint url range?

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,940

    Re: Function for FileLen

    I can't answer as I don't use Sharepoint. No longer employed and have no need. I use the Path associated with the sub folders I am searching. Suggest you try and see what happens.

  5. #5
    Registered User
    Join Date
    06-23-2014
    Location
    MidWest, USA
    MS-Off Ver
    2016
    Posts
    89

    Re: Function for FileLen

    I'd vastly prefer to use local pc file directories as the code seems to work much better. Sharepoint is nothing but problematic in terms of how well automation code seems to work for me. Thanks for the suggestions though, I'll give it a try here.

  6. #6
    Registered User
    Join Date
    06-23-2014
    Location
    MidWest, USA
    MS-Off Ver
    2016
    Posts
    89

    Re: Function for FileLen

    Yeah, this code is throwing an error, I think due to Sharepoint. The more research I do on this issue, the more I think employing this type of code with files stored on Sharepoint will be much more difficult.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. COUNTUNIQUE Function in Google Sheets; Excel lacks a direct counterpart to this function?
    By PivotTablePSHomage in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-18-2018, 05:27 AM
  2. Replies: 2
    Last Post: 04-23-2017, 12:04 AM
  3. Calling function inside function. (aka nested function)
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2015, 05:58 AM
  4. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  5. [SOLVED] Using Offset function as the array in the PercentRank function is giving wrong result
    By Bobneil in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-06-2013, 09:29 PM
  6. Replies: 1
    Last Post: 03-21-2012, 11:22 AM
  7. [SOLVED] FileLen with very large files
    By simonc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-07-2005, 09:10 PM

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