Jander Friebe
Jander Friebe

Reputation: 23

Excel process don´t close VBA

I saw my question popping up quite a few times, but none of the answer worked for me.. So let me introduce you to my Problem:
I run my Makro (just a single Sub) from an Word Document. As a helping hand I´ll open a new Excel file, format things from my clipboard in it and then bring it back to the Word file.
But after everything is done, nobody can see, that I used Excel.
BUT it wont close as a process, as I want it to. I tried every method I saw, but nothing seems to work:

Application.ScreenUpdating = False

' declare Excel Objects
Dim appExcel As Excel.Application
Dim wbCalculator As Workbook
Dim wsCalculator As Worksheet

' initialize Excel Objects
Set appExcel = New Excel.Application
Set wbCalculator = Excel.Workbooks.Add
Set wsCalculator = wbCalculator.Sheets(1)

...
"My totally efficient and beautiful Code"
...

' Close Excel
wbCalculator.Saved = True
Set wsCalculator = Nothing
wbCalculator.Close False
Set wbCalculator = Nothing
appExcel.Quit
Set appExcel = Nothing

Application.ScreenUpdating = True

I hope you can help me out with this one:)

Upvotes: 0

Views: 75

Answers (1)

tigeravatar
tigeravatar

Reputation: 26640

Going to highlight two lines of code here:

Set appExcel = New Excel.Application
Set wbCalculator = Excel.Workbooks.Add

Here you can see that you created an object named appExcel and the intent is to use that object. However, you then simply reference the Excel object model directly instead of appExcel. This means you now have an extra Excel instance under the same process that you never again address or close. Try changing it to:

Set appExcel = New Excel.Application
Set wbCalculator = appExcel.Workbooks.Add

Upvotes: 1

Related Questions