+ Reply to Thread
Results 1 to 9 of 9

slow vba running with xlsm files

  1. #1
    Registered User
    Join Date
    08-01-2013
    Location
    Verona - Italy
    MS-Off Ver
    Excel 2007-2010-2013
    Posts
    33

    slow vba running with xlsm files

    Hi all,

    i have a simple question regarding vba code involving opening/eleboration/closing of different excel workbooks' format. I saw that with xls/xlsx the macro works with relatively high speed, but it is very slow when it comes to xlsm file. Is there an explanation? Does a command which enhance speed for xlsm file exist?

    Thank you very much

    Diego

  2. #2
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: slow vba running with xlsm files

    Hey Diego,

    There's nothing like that a command runs faster in xls and slower in xlsm. As we know, xls, xlsm, xlsb are just file extensions that tells us what kind of data is stored in those files. xls are basically older versions of Excel app. Since office 2007, the types are more specific in Excel which can clearly intimate what kind of data is available inside Excel app by just looking at it. From 2007 onwards, there has been a collaboration of Excel with Windows ZIP, thus, forming its structure as XLS + ZIP = XLSX. This was done in order to reduce the file size by compressing it. Microsoft has also adapted XML to form the base structure for the app thus making it more light and dynamic. XLSM is same as XLSX, but with an extra feature that it is specifically for allowing the macros to be stored within the file. And yeah, XLSX can't store macros.

    The speed of macros actually depends on many things:
    1. CPU
    2. RAM
    3. Application Settings
    4. And last but not least, your code.

    There are other things too but the above four are the major ones that has an effect on the speed of a macro. We can't help on the first two ones as those will involve costs but can manage the last two. Following is a code you can implement in your application to speed up by making sure no unnecessary steps get involved when you're running the codes.

    Please Login or Register  to view this content.
    The first ones, disables flickering of screen when macro runs. The second line makes sure sheet doesn't calculates when running macro. You could use Application.Calculate to calculate the cells when necessary. Third step stops prompting with unnecessary alerts like Allow-merging-Pop-ups. And last one makes sure no event gets triggered when the data is manipulated in the sheet. Enable it explicitly using Application.EnableEvents = True when you need the events to be triggered. I personally use this macro to make sure all of the settings are set to speed up my macro and I explicitly command if there special cases like calculations or triggering of an event.

    On the last part, it depends on how you write code. There cannot be set instructions to use this or that when writing a code, because there's no restrictions to it. Its just our practices that makes a difference. Like for example, I try my best to avoid maximum number of loops as we all know, they eat a hell lot of memory, but in some cases they can be the best approach. There are always alternatives, so just find one for your own self.

    If you post your codes, one or a few people in this forum, might be able to help find the part of the code that's making the processing slow. Cheers! Hope, you've got your answer.
    Last edited by codeslizer; 08-29-2013 at 10:37 PM.
    cOdEsLiZeR - Back after a long break.. Let's sLiZe some more cOdEs!!

  3. #3
    Registered User
    Join Date
    08-01-2013
    Location
    Verona - Italy
    MS-Off Ver
    Excel 2007-2010-2013
    Posts
    33

    Re: slow vba running with xlsm files

    Hi codeslizer,

    thank you for your clear answer, I've tryed all your suggestions and also the "read-only" opening with a line

    dim FilePath as string
    FilePath="C:\trial.xlsm"
    Workbooks.Open FileName:=FilePath, ReadOnly:=True

    My macro involves basically opening file/ copy/paste /close file operations but the difference within the two formats (xlsx vs xlsm) is evident (about half a second with xlsx, about 5 seconds with xlsm) so I solved my problem by running an extra macro which creates an xlsx copy of all xlsm files (fortunately it is not necessary file format).

    Thank you a lot anyway

    Diego

  4. #4
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: slow vba running with xlsm files

    Mm.. I believe that's because of the security issues. As xlsm stores code, the application first checks if the file has the authentication to allow the codes to run by the user. If the user has previously allowed the run then it is considered as authentic if macro settings is set to "Enable All Macros". For xlsx, there is no need of authentication as it doesn't allow storage of any codes when saved and so would always be safe to open it. The reason is because files can be designed with macros to steal the information from a client's system if the creator's intentions aren't good. So, this might be the case, I believe..

    Open for thoughts!

  5. #5
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: slow vba running with xlsm files

    Quote Originally Posted by Dturazza View Post
    My macro involves basically opening file/ copy/paste /close file operations but the difference within the two formats (xlsx vs xlsm) is evident (about half a second with xlsx, about 5 seconds with xlsm)
    I suspect you will be having any On Workbook Open Event on those .xlsm files which may be the root cause of this problem.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  6. #6
    Registered User
    Join Date
    08-01-2013
    Location
    Verona - Italy
    MS-Off Ver
    Excel 2007-2010-2013
    Posts
    33

    Re: slow vba running with xlsm files

    Hi Sixthsense,

    How can I disable "On Workbook Open Event" on xlsm file? Another observation is that the cose is slow not only in the file opening, but also in the copy/paste operations...and moreover...Microsoft Security Essential have been istalled on my pc...can it be also a rootcause?

    Thanks all!

    Diego

  7. #7
    Registered User
    Join Date
    08-01-2013
    Location
    Verona - Italy
    MS-Off Ver
    Excel 2007-2010-2013
    Posts
    33

    Re: slow vba running with xlsm files

    Yeah I found it!

    The problem is that with the xlsm the excel interacts with the macro in some way, even if the macro does not calculate anything (I set calculation to manual...). I adopted the following code found at http://social.msdn.microsoft.com/For...cel-from-vbnet

    Please Login or Register  to view this content.
    I'm so happy!!
    Thanks for the aid!
    Diego
    Last edited by Dturazza; 08-30-2013 at 10:07 AM. Reason: definitive answer

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: slow vba running with xlsm files

    Glad you fixed it and thanks for the feedback

    Also please select Thread Tools from the menu link above and mark this thread as SOLVED.

  9. #9
    Registered User
    Join Date
    03-17-2014
    Location
    Vietnam
    MS-Off Ver
    Excel 2013
    Posts
    1

    Re: slow vba running with xlsm files

    I have problem with excel 2013 vba too

+ 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. .XLSM Slow issues
    By jaimie1664 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2013, 10:27 AM
  2. Macro to hide/unhide cells not running or running slow
    By mbp727 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2013, 04:22 PM
  3. Problem day 2 running a scheduled .xlsm-macro
    By svenalgo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2012, 05:02 AM
  4. vlookup to .xlsm macro is incredibly slow
    By jrussell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2009, 03:43 PM
  5. Running vblookup between two .xlsm documents
    By D_Rennie in forum Excel General
    Replies: 8
    Last Post: 05-19-2009, 10:56 PM

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