+ Reply to Thread
Results 1 to 3 of 3

Excel 2007 takes forever to export Data

Hybrid View

  1. #1
    Registered User
    Join Date
    12-03-2008
    Location
    USA
    Posts
    2

    Excel 2007 takes forever to export Data

    I have a macro that is used to export data to a ~ delimited file. The macro runs fine with Excel 2003. However when we try to use it in an excel 2007 file it takes forever to export the data. I.E. in excel 2003, I can export 65k rows of data in just 6 minutes. However it took 53 minutes to export 45k rows in excel 2007. I would appreciate any help with solving this issue. The macro code is below:

    Sub Export_Local_TP_Source()
    'Delete existing tp_source.txtx file
    
    On Error Resume Next
    Kill "c:\temp\TP_source.txt"
    On Error GoTo 0
    
    
    '
    'Start of actual export
    'Public Sub CharacterSV()
            Const DELIMITER As String = "~"
            Dim myRecord As Range
            Dim myField As Range
            Dim sOut As String
            
            Open "c:\temp\TP_source.txt" For Output As #1
            For Each myRecord In Range("A2:A" & _
                        Range("A" & Rows.Count).End(xlUp).Row)
                With myRecord
                    For Each myField In Range(.Cells, _
                            Cells(.Row, Columns.Count).End(xlToLeft))
                        sOut = sOut & DELIMITER & myField.Text
                    Next myField
                    Print #1, Mid(sOut, 2)
                    sOut = Empty
                End With
            Next myRecord
            Close #1
        'End Sub
    'end of export
    MsgBox "File exported to: c:\temp\TP_source.txt", vbOKOnly
    
    End Sub

  2. #2
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    VBA in 2007

    Hi

    Although not much consolation I have found the same thing happening, with macros running much slower than in previous versions, around 10 times slower on average.

    I have not been able to find any way to speed things up.

    Regards

    Jeff

  3. #3
    Registered User
    Join Date
    12-03-2008
    Location
    USA
    Posts
    2

    Excel 2007 VBA Macro takes forever

    Well I think it has something to do with the way it is calculating the number of columns.

    I tried the following to see how many rows/columns it was counting

    sub test()
     rn=(range("A" & Rows.count).end(xlUp).row)
     cn=columns.count
     msgBox ("rows - " & rn & ": Columns - " &cn)
    End Sub
    It returns a total of 16384 columns even thoul I am only using 15.

    I tried to use
    cn= range(.cells, cells(.row, columns.count).end(xlToLeft))
    to count the columns but it errored.

    If this is the case, how can I tell it only to use the used columns (15 in my case) without hard coding 15?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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