Results 1 to 2 of 2

[Excel 2010] Performance issues scanning external documents for text

Threaded View

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    5

    Question [Excel 2010] Performance issues scanning external documents for text

    Hey guys,
    i need ur help in order to solve a problem with my code.
    The goal is, starting from a compiled table in excel, to scan a single column and find, for each cell value, a match in the documents contained in a specific folder.
    The code i wrote works but i have encountered many problems with the performance of the execution.
    The code:

    • Read the entire 3rd column and populate a collection
    • When the excel reading is done it pass to the file management opening each one and searching it for each keyword previously stored in the collection
    • When done with files search the control pass again to the excel in order to update an adiacent column with the search results

    Now about the numbers: i have to search around 8-10 thousand values in about 800-1.000 word files.
    The execution time, in seconds, is around
    Formula: copy to clipboard
    values * documents / 12
    , for the specific case we're talking of 4 days of runtime, lol
    Any suggestion about what to use (structures, search methods, etc..) to improve timewise?

    Here the code:

    
    Function test()
    
        Dim elencoPartizioni As New Collection
        Dim tempPartizione As CPartizione
        Dim oWordDoc, oWordApp, rngStory As Object
        Dim searchPattern, fileExtensionPattern, sourceFolder, filePath, sFileName, searchResults As String
        Dim idRow As Long
        Dim startTime, endTime As Date
        
        
        sourceFolder = "C:\Users\itals007\Desktop\note\"
        fileExtensionPattern = "*.doc?"
        filePath = Dir$(sourceFolder & fileExtensionPattern)
        Set oWordApp = CreateObject("Word.Application")
        oWordApp.Visible = False
        startTime = Now
        
        idRow = 8
        While Cells(idRow, 3).value <> ""
            
            Set tempPartizione = New CPartizione
            tempPartizione.nomePartizione = LCase(Cells(idRow, 3).value)
            On Error Resume Next
            elencoPartizioni.Add tempPartizione, tempPartizione.nomePartizione
            
            idRow = idRow + 1
        
        Wend
        
    '*************************************************************************************
        
        While filePath <> ""
            
            On Error GoTo errorHandling
            sFileName = sourceFolder & filePath
            Set oWordDoc = oWordApp.Documents.Open(sFileName)
            
            Dim iPartizione As CPartizione
            
            For Each iPartizione In elencoPartizioni
                
                If LCase(Left(oWordDoc.Name, InStrRev(oWordDoc.Name, ".") - 1)) = LCase(iPartizione.nomePartizione) Then
                
                    iPartizione.presenzaNotaOperativa = "Presenti"
                    iPartizione.elencoMatchNoteOperative.Add oWordDoc.Name
                            
                End If
                
                For Each rngStory In oWordDoc.StoryRanges
    
                    With rngStory.Find
                    
                        .Text = iPartizione.nomePartizione
                        .Wrap = 1
                        .Execute
                    
                        If .found And iPartizione.presenzaNotaOperativa <> "Presenti" Then
                        
                            iPartizione.elencoMatchNoteOperative.Add oWordDoc.Name
                            iPartizione.presenzaNotaOperativa = "Parziali"
                            Exit For
                        
                        End If
                    
                    End With
                
                Next
            
            Next
            
            oWordDoc.Close
            filePath = Dir$()
            
    errorHandling:
                
            If Err.Number <> 0 Then
                
                MsgBox "Errore", vbCritical
                
            End If
    
        Wend
        
        oWordApp.Quit
        Set oWordDoc = Nothing
        Set oWordApp = Nothing
        
        idRow = 8
        While Cells(idRow, 3).value <> ""
        
            Cells(idRow, 2).ClearComments
            
            If elencoPartizioni.Item(LCase(Cells(idRow, 3).value)).presenzaNotaOperativa = "" Then
            
                Cells(idRow, 2).value = "Non presenti"
            
            Else
            
                Cells(idRow, 2).value = elencoPartizioni.Item(LCase(Cells(idRow, 3).value)).presenzaNotaOperativa
                Cells(idRow, 2).AddComment elencoPartizioni.Item(LCase(Cells(idRow, 3).value)).elencoMatchNote
                Cells(idRow, 2).Comment.Shape.TextFrame.AutoSize = True
            
            End If
                
            idRow = idRow + 1
        
        Wend
        
        endTime = Now
        
        MsgBox "Esecuzione in " & DateDiff("s", startTime, endTime) & " s"
        
    End Function
    Last edited by Prejdickty; 09-05-2014 at 09:35 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. External word documents last saved date in Excel cells.
    By tazman_il in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-25-2024, 10:28 PM
  2. Importing Data from Multiple Excel Documents Into a Single File MAC Issues
    By Kal_2013 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-04-2013, 04:16 PM
  3. XL 2010 performance issues
    By Stevef8 in forum Excel General
    Replies: 0
    Last Post: 05-31-2012, 03:29 PM
  4. VLOOKUP performance issues
    By jbernhard in forum Excel General
    Replies: 3
    Last Post: 01-11-2010, 06:50 PM
  5. Issues copying excel charts to word documents - using Excel VBA
    By Frankie in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-20-2006, 10:40 AM

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