Application.Quit Help

AndFel

New Member
Joined
Jun 19, 2014
Messages
4
Hi
I’m writing an Outlook macro that looks in the incoming mails and, selects the specific mails, opens the attachments (only excel files), and copy the contents into another workbook, the process is really simple. Anyway after I close the workbooks, and the application, the Applications keeps rolling in the system!
I have already read other post in the forum, suggesting to use System.Runtime.InteropServices.Marshal.ReleaseComObject...., but it doesn’t work in the Microsoft Visual Basic Editor of Outlook, or I don’t know how make it work.
I don’t know if there is another way to end this procces? Could you help me pls??

Public Function StockReportXlabel(ByVal newStockReport As Attachment)
Dim xlsApp as Excel.Application
Dim DataModel As Excel.Workbook
Dim newFile As Excel.Workbook
Dim filePath As String, srLines As Double, fileName As String

filepath = i save the attachement in a local folder and gets the path


xlsApp.Visible = False
xlsApp.DisplayAlerts = False
xlsApp.ScreenUpdating = False

Set DataModel = xlsApp.Workbooks.Open(fileName:=DATA_PREPARATION_PATH, ReadOnly:=False)
Set newFile = xlsApp.Workbooks.Open(fileName:=filePath, ReadOnly:=True)
newFile.Activate
Range("A6", Cells(Range("A65536").End(xlUp).Row, 9)).Copy
DataModel.Activate
Range("A2").Select
ActiveCell.PasteSpecial xlPasteValuesAndNumberFormats
xlsApp.CutCopyMode = False
newFile.Close savechanges:=False
Set new File = Nothing

srLines = Range("A65536").End(xlUp).Row
ActiveWorkbook.Names("SR_New").RefersToR1C1 = "=StockReport!R2C1:R" & srLines & "C9"
Range("A1").Select

DataModel.Close savechanges:=True
Set DataModel = Nothing
xlsApp.Quit
Set xlsApp = Nothing
End Function

<tbody>
</tbody>

Thanks!!!
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Welcome to MrExcel.

Why are you using unqualified Excel objects in Outlook code, eg Range, Cells, ActiveCell and ActiveWorkbook?
 
Upvote 0
I use the ddl for Microsoft Excel 12.0 Object Library... (Tools-->References-->and i search it)... It makes it simple for me
 
Upvote 0
You still have to properly qualify your objects or you will see the behaviour you describe. Try something like:

Code:
Public Function StockReportXlabel(ByVal newStockReport As Attachment)
Dim xlsApp As Excel.Application
Dim DataModel As Excel.Workbook
Dim newFile As Excel.Workbook

Dim filePath As String, srLines As Double, fileName As String

filepath = i save the attachement in a local folder and gets the path


xlsApp.Visible = False
xlsApp.DisplayAlerts = False
xlsApp.ScreenUpdating = False

Set DataModel = xlsApp.Workbooks.Open(fileName:=DATA_PREPARATION_PATH, ReadOnly:=False)
Set newFile = xlsApp.Workbooks.Open(fileName:=filePath, ReadOnly:=True)
With newFile.ActiveSheet
    .Range("A6:I" & .Cells(.Rows.Count, "A").End(xlUp).Row).Copy
End With

DataModel.Range("A2").PasteSpecial xlPasteValuesAndNumberFormats

xlsApp.CutCopyMode = False
newFile.Close savechanges:=False

Set newFile = Nothing

With DataModel
    With .ActiveSheet
        srLines = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    .Names("SR_New").RefersToR1C1 = "=StockReport!R2C1:R" & srLines & "C9"
    .Close savechanges:=True
End With

Set DataModel = Nothing
xlsApp.Quit
Set xlsApp = Nothing
End Function
 
Upvote 0
Glad to help. Welcome to the forum, by the way! :)
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,225
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top