Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating Excel using Access Code Problem

Status
Not open for further replies.

Sech

Programmer
Jul 5, 2002
137
GB
I am currently developing a database which requires an Excel file of numeric data to be exported, but also with formatting of this data to 2 decimal places. I discovered that the best way to do this is to alter the export file itself using Access code after it has been created. However I am having trouble closing down Excel in the background after the changes. I open up the Worksheet, make the changes and then save and close it all down using the below code:
Code:
'Save the workbook
oxlWorkbook.Save

'Close the workbook and quit the Excel application
oxlWorkbook.Close False
oxlApp.Quit
    
'Clear vars
Set oxlWorksheet = Nothing
Set oxlWorkbook = Nothing
Set oxlApp = Nothing
However when I then go to Windows Explorer and double click on the export file to view the data before closing down the database it does not open as it is still remaining open in the background invisibly. Once I exit the database this seems to close the invisible Excel down also and I can then open the file fine. Can anyone tell me how to shut down the invisible Excel and the file so that I can immediately open the file using windows explorer? The only extra reference I have used in the database is Microsoft Excel 8.0 Object Library.
 
I have found out that the problem of Excel not closing is to do with the formatting of the cells to 2 decimal places. The code I am currently using to do this (I don't know whether it's correct or not) is:
Code:
'Set number formats to 2 decimal places
oxlWorksheet.Cells.Select
Selection.NumberFormat = "0.00"
When I rem out this code and run the process Excel appears to close fine. My theory is that Excel is trying to close before the formatting of the cells has finished properly so it is not closing. Does anyone know any command to get the formatting to complete before the code continues?
 
Hi Sech

See my reply to your prev. thread, I think it might solve the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top