Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Unreleased object reference?
Message
 
 
À
Tous
Information générale
Forum:
Visual Basic
Catégorie:
COM, DCOM et OLE automation
Titre:
Unreleased object reference?
Divers
Thread ID:
00659048
Message ID:
00659048
Vues:
45
I'm trying to create an Excel file through automation from VB and attach the file created to an e-mail but having problem with object reference not releasing.

The Excel file is created fine but when the e-mail pops up with the file attached, I can't immediately open the file. I get what seems like Excel but not completely opened up.

It appears my reference to the Excel object isn't released from memory. Can anyone point to someplace in code where I might of missed? The code is below.
Public Sub CreateExcelFile()
    Dim excelApp As Excel.Application
    Dim excelBook As Workbook
    Dim excelSheet As Worksheet
    Dim excelRange As Range
    Dim oEmail As SendEmail
    
    Set excelApp = New Excel.Application
    If Err.Number <> 0 Then
         Set excelApp = CreateObject("Excel.Application")
    End If
    
    Set excelBook = Workbooks.Add
    Set excelSheet = Excel.Worksheets.Add(Before:=Worksheets(1))
    If Val(excelApp.Application.Version) >= 8 Then
        Set excelSheet = excelApp.ActiveSheet
    Else
        Set excelSheet = excelApp
    End If
            
    With excelSheet.Cells.Font
        .Name = "Arial"
        .Size = 8
    End With
    
    ' Write field header
    With excelSheet
        .Cells(1, 1) = "Clientname"
        ' code to insert more text here
    End With

    excelSheet.Columns("A:L").EntireColumn.AutoFit
    
    excelBook.SaveAs strFilename
    excelBook.Close
    excelApp.Quit
    
    Set excelSheet = Nothing
    Set excelBook = Nothing
    Set excelApp = Nothing

    ' send email
    Set oEmail = New SendEmail
    With oEmail
        .SendTo = ""
        .Subject = "Testing"
        .Body = "test"
        .Attachments strFilename
        .Show
    End With
End Sub    
It's "my" world. You're just living in it.
Répondre
Fil
Voir

Click here to load this message in the networking platform