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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Welcome to MrExcel.

Why are you using unqualified Excel objects in Outlook code, eg Range, Cells, ActiveCell and ActiveWorkbook?
 

AndFel

New Member
Joined
Jun 19, 2014
Messages
4
I use the ddl for Microsoft Excel 12.0 Object Library... (Tools-->References-->and i search it)... It makes it simple for me
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
39,057
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
39,057
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Glad to help. Welcome to the forum, by the way! :)
 

Forum statistics

Threads
1,171,650
Messages
5,876,664
Members
433,205
Latest member
jabin1991

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
Top