Results 1 to 12 of 12

VBA running slow

Threaded View

  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

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim varDoc As Object
    Dim endRow As Long
    Dim Rng As Range, c As Range
    
    Dim FilePath, currPath As String
    Application.EnableEvents = False
    endRow = Cells(ActiveSheet.Rows.Count, 3).End(xlUp).Row ''Find end row in column C
    
    Set Rng = Range(Cells(3, 3), Cells(endRow, 3)) ''check each used cell in column C
     For Each c In Rng '' For each cell in range
       If c.Value <> vbNullString And c.Hyperlinks.Count = 0 Then  ''test to see if cell not empty and no hyperlink to speed loop up
     
    
     ''Test to see if file exists and create on if it doesn't
      currPath = ThisWorkbook.Path
      If currPath = vbNullString Then currPath = "C:\Users\Downloads\Tracker" & Cells(c.Row, 3).Value ''save folder to desktop if file isn't saved
        folderExists currPath, Cells(c.Row, 3).Value
        FilePath = currPath & "\" & Cells(c.Row, 3).Value
        Set varDoc = CreateObject("Word.Application")
    
                      varDoc.Visible = True
                      ActiveSheet.Cells(c.Row, 3).Copy
                      varDoc.Documents.Add
                      varDoc.Selection.Paste
                      varDoc.ActiveDocument.SaveAs FileName:=FilePath & "\" & Cells(c.Row, 3).Value
                      
        
    
       'create directories if needed
        Call MakeFolders(currPath)
                      
    
       ''if the folder wasn't found and one was created in the folderExists function, add a hyperlink
        ActiveSheet.Hyperlinks.Add Anchor:=c, Address:=currPath & "\" & Cells(c.Row, 3).Value, TextToDisplay:=c.Value
    
    
        Else: End If
    
    Next c
    
    
    Set Rng = Nothing
    Application.EnableEvents = True
    
    End Sub


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

    and works fine (as you would expect)

    Function MakeFolders(MyStr As String)
    'Author:    Jerry Beaucaire
    'Date:      7/14/2010
    'Summary:   Create directories and subdirectories based
    '           on the text strings fed to the function
    '           This version is to be called by other macros
    Dim MyArr   As Variant
    Dim pNum    As Long
    Dim pBuf    As String
    
    On Error Resume Next
      
        MyArr = Split(MyStr, "\")
        pBuf = MyArr(LBound(MyArr)) & "\"
        For pNum = LBound(MyArr) + 1 To UBound(MyArr)
            pBuf = pBuf & MyArr(pNum) & "\"
            MkDir pBuf
        Next pNum
    
    End Function
    I look forward to any help or direction
    Last edited by Toonies; 11-25-2013 at 06:55 AM. Reason: Added Sample File

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