PC Review


Reply
Thread Tools Rate Thread

code to check file size everytime an Excel file is opened

 
 
Kaiser
Guest
Posts: n/a
 
      30th Jul 2006
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 With Quote
 
 
 
 
raypayette
Guest
Posts: n/a
 
      30th Jul 2006

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


--
raypayette


------------------------------------------------------------------------
raypayette's Profile: http://www.excelforum.com/member.php...o&userid=29569
View this thread: http://www.excelforum.com/showthread...hreadid=566359

 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      30th Jul 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A new sequence number in file everytime it is opened =?Utf-8?B?VGlnZXIgQ2xhdw==?= Microsoft Excel Worksheet Functions 1 15th Jun 2005 03:37 PM
Closing an opened Excel file, Code? =?Utf-8?B?TWF0dA==?= Microsoft Access 0 25th Oct 2004 08:01 PM
Excel file doubling in size everytime a change and save is made Alan Murray Microsoft Excel Crashes 1 25th May 2004 06:02 PM
how to check through Access whether some Excel file is opened Alex Microsoft Access External Data 2 20th Jan 2004 01:13 AM
how to check through Access whether some Excel file is opened Alex Microsoft Access VBA Modules 2 20th Jan 2004 01:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:16 PM.