+ Reply to Thread
Results 1 to 12 of 12

VBA running slow

  1. #1
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    VBA running slow

    Hi and thanks for looking at my thread.

    I have the following VBA which works to a point, however it is running slow.

    It creates a New subfolder within a Folder based on cell value in column C.

    I would like it to start from "C3" Down. (not quite sure how to get it there)

    then it creates a word document and places that inside the newly created folder, then creates a hyperlink to the folder.

    I have pieced the vba together more through trial and error.


    Trial.xls

    Please Login or Register  to view this content.


    The 2nd part of the code is written by Jerry Beaucaire

    and works fine (as you would expect)

    Please Login or Register  to view this content.
    I look forward to any help or direction
    Last edited by Toonies; 11-25-2013 at 06:55 AM. Reason: Added Sample File

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA running slow

    Hi

    from experience it takes an inordinate amount of time to open word from vba,

  3. #3
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: VBA running slow

    Hi thanks for the info, I will take this on board.

    Still looking to start Range in column C from "C3"

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208

    Re: VBA running slow

    Quote Originally Posted by Toonies View Post
    Still looking to start Range in column C from "C3"
    They way your For Each loop is written should in fact loop from C3 to the last cell in column C that is not empty. What are you experiencing that is showing otherwise?

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: VBA running slow

    Why create a new instance of Word each time you loop?

    Try creating one instance outside the loop and use that in the rest of the code.
    If posting code please use code tags, see here.

  6. #6
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: VBA running slow

    jasoncw sorry it does as you have said

  7. #7
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: VBA running slow

    Norie

    I want a Word Doc for each employee, or would it be easier if I used a Word Template and copied that when creating individual folders and hyperlink instead?

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: VBA running slow

    You don't need a separate instance of Word for each document.

    Use one instance of Word to create all the documents.

  9. #9
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: VBA running slow

    so simply create a Template and upon the creation of the employee folder copy Template to folder

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA running slow

    put this bit:
    Please Login or Register  to view this content.
    outside of the for loop

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: VBA running slow

    That's not what I'm suggesting.

    I'm suggesting you move this line of code outside the loop.
    Please Login or Register  to view this content.
    This line creates a new instance of Word every time the loop loops.

    So if it loops 10 times then you'll end up with 10 instances of Word.

    That's not a good idea and since it take up time to create each of the instances of Word it's probably one of the reasons the code is running slow.

    By the way, why is this code in a worksheet change event?

    Do you want it to run every time anything is changed on the worksheet?

  12. #12
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: VBA running slow

    I have looked at the worksheet change event and place this bit of code at the beginning
    Please Login or Register  to view this content.
    so it now only fires when column cell values changed

+ 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. Macro is running real slow and makes navigating the worksheet really slow after execution.
    By MichWolverines in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2013, 04:29 PM
  2. worksheet is running VERY slow!
    By tsiguy96 in forum Excel General
    Replies: 3
    Last Post: 09-29-2013, 07:19 PM
  3. 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
  4. vba code running too slow
    By hitsujicute in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2013, 06:00 PM
  5. [SOLVED] VBA running VERY slow
    By stuart_bisset@yahoo.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-01-2005, 12:05 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