473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VBA Module(Access) exe32-not-closing-in-task-manager

What's wrong with this function? excel is not closing in task manager.

Expand|Select|Wrap|Line Numbers
  1. Function formatExcel()
  2.     Dim FileName As String
  3.     FileName = "C:\This file\queryCentering.xlsx"
  4.     Set xl = New Excel.Application
  5.     Set wb = xl.Workbooks.Open(FileName)
  6.     With wb.Sheets(1)
  7.         Columns("E:E").Select
  8.         Selection.NumberFormat = "m/d/yyyy"        
  9.  
  10.         Columns("C:C").HorizontalAlignment = xlCenter
  11.  
  12.     End With
  13.     wb.Save
  14.     wb.Close True
  15.     Set wb = Nothing
  16.     Set xl = Nothing
  17.     xl.Quit
  18.    End Function
Sep 7 '16 #1

✓ answered by PhilOfWalton

I think you are ding things in the wrong order

Try
Expand|Select|Wrap|Line Numbers
  1.     XL.Application.Quit           ' When you finish, use the Quit method to close
  2.     Set XL = Nothing  
  3.  
Phil

2 725
PhilOfWalton
1,430 Expert 1GB
I think you are ding things in the wrong order

Try
Expand|Select|Wrap|Line Numbers
  1.     XL.Application.Quit           ' When you finish, use the Quit method to close
  2.     Set XL = Nothing  
  3.  
Phil
Sep 7 '16 #2
ADezii
8,834 Expert 8TB
Like Phil has already said, it's all in the order. You are releasing all Resources assigned to an Object Variable representing an Instance of the Excel Application, then in the very next step trying to execute the Quit Method of this very Object. The only problem is that the Object no longer exists. I am very surprised that you did not receive the following Error:
Expand|Select|Wrap|Line Numbers
  1. Run-time Error 91
  2. Object Variable or With block variable not set
Sep 7 '16 #3

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.