+ Reply to Thread
Results 1 to 3 of 3

code to check file size everytime an Excel file is opened

  1. #1
    Kaiser
    Guest

    code to check file size everytime an Excel file is opened

    Hello,

    Every time any Excel file is opened, I'd like Excel to automatically
    check the size of the file being opened and if it is greater than say,
    5mb, I'd like Manual calculate to be turned on. Is there a way to do
    this?

    The workbook_open event etc. wouldn't work since then I would have to
    include this macro in every single Excel workbook I ever create or that
    already exists. Having the macro in the xlstart folder etc. doesn't
    work either since the macro there doesn't seem to be run before the
    file is opened.

    Is there a way to do this using VBA? or VB6? or at the command line?

    Thanks,


  2. #2
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667

    code to check file size everytime an Excel file is opened

    Sub FileSize()
    Dim oFSO
    Dim oFile
    Dim oSourceFile
    oSourceFile = "D:/Excel/test.xls"
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFile = oFSO.GetFile(oSourceFile)
    If oFile.Size > 5000000 Then
    Application.Calculation = xlManual
    End If
    Set oFile = Nothing
    Set oFSO = Nothing
    End Sub
    Best regards,

    Ray

  3. #3
    Tom Ogilvy
    Guest

    Re: code to check file size everytime an Excel file is opened

    It might be easier to set calculation to manual, then if the file is small
    enough, turn it back on after the file is opened.

    you would need to use application level events to turn it on.

    http://www.cpearson.com/excel/appevent.htm

    Do that in the personal.xls or an addin.

    --
    Regards,
    Tom Ogilvy

    "Kaiser" <[email protected]> wrote in message
    news:[email protected]...
    > Hello,
    >
    > Every time any Excel file is opened, I'd like Excel to automatically
    > check the size of the file being opened and if it is greater than say,
    > 5mb, I'd like Manual calculate to be turned on. Is there a way to do
    > this?
    >
    > The workbook_open event etc. wouldn't work since then I would have to
    > include this macro in every single Excel workbook I ever create or that
    > already exists. Having the macro in the xlstart folder etc. doesn't
    > work either since the macro there doesn't seem to be run before the
    > file is opened.
    >
    > Is there a way to do this using VBA? or VB6? or at the command line?
    >
    > Thanks,
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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