dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Excel Memory Problem

  1. #1
    Join Date
    May 2001
    Posts
    22

    Excel Memory Problem

    I am exporting data from a recordset to Excel. The following code is a sub within the class that I'm using for the export:

    Private Sub AddText(strSheet As String, strCell As String, ByVal strText As Variant, intFont As Integer, Optional sAlignment As Integer = xlLeft, Optional blnMerge As Boolean, Optional strSecCell As String, Optional blnBold As Boolean)

    Dim wkRange As Excel.Range

    Set wkRange = wkSheet.Range(strCell)

    With wkRange.Font
    .Name = "Arial"
    .Size = intFont
    If blnBold Then
    .FontStyle = "Bold"
    End If
    End With

    If blnMerge Then
    wkSheet.Range(strCell & ":" & strSecCell).Merge
    wkSheet.Range(strCell & ":" & strSecCell).HorizontalAlignment = sAlignment
    Else
    wkRange.HorizontalAlignment = sAlignment
    End If

    wkRange = strText
    DoEvents

    Set wkRange = Nothing

    End Sub

    I have declared a global variable for the Excel.Application object, a global variable for the Excel.Workbook object and a global variable for the Excel.Worksheet object in the class.

    The code loops through the recordset and calls the AddText sub each time to print the text. Half way through execution Excel will run out of memory - I believe it is this section of code that is causing the problem. Can anyone spot anything obviously wrong with my code?

    Thanks

  2. #2
    Join Date
    Aug 2000
    Location
    Essex, Uk
    Posts
    1,214
    cant see anything obvious. What is your reasoning to think that this is the problem. Can you post the code that calls it.

  3. #3
    Join Date
    May 2001
    Posts
    22
    When I comment out the following lines:

    If blnMerge Then
    wkSheet.Range(strCell & ":" & strSecCell).Merge
    wkSheet.Range(strCell & ":" & strSecCell).HorizontalAlignment = sAlignment
    Else
    wkRange.HorizontalAlignment = sAlignment
    End If

    ...it works fine without any memory problems?!?

    Calling code:


    Do While Not objDb.rs.EOF
    AddText "Test", "K" & intRow, objDb.rs(5), 10, xlCenter
    AddText "Test", "L" & intRow, objDb.rs(6), 10, xlCenter
    AddText "Test", "N" & intRow, objDb.rs(7), 10, xlCenter
    lngHours = lngHours + objDb.rs(5)
    intMins = intMins + objDb.rs(6)

    intRow = intRow + 1
    objDb.rs.MoveNext
    Loop


    Thanks
    David

  4. #4
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    651
    What version of Windows are you running? Here's a quote from an article posted at MSDN:

    'Microsoft Windows 95 and Windows 98 have a 64K limitation on interface requests. If you reach or exceed this 64k limit on interface requests, the Automation server (Excel) might stop responding or you might receive errors indicating low memory.'

    http://support.microsoft.com/default...b;EN-US;247412
    I'd rather be wakeboarding...

  5. #5
    Join Date
    May 2001
    Posts
    22
    Malleyo,

    I think you may have found the answer - I'm using a Win98 machine so I'll be trying the app on a 2000 machine to see if the problem persists.

    Thanks for the link!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)