Help Closing Excel Workbook from MS Access

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
647
Office Version
  1. 2016
Platform
  1. Windows
Hi
I need a separate proceedure to close an already open workbook in excel 2010 from ms access 2010.
This is what I have but I cannot get it to work Thanks

Sub CloseExcel()
Dim wb As Excel.Workbook
Dim xlApp As Excel.Application

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True

Set wb = xlApp.Workbooks.Open("C:\Payroll_Summary.xls")
wb.Close True
xlApp.Quit
Set xlApp = Nothing

End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
That should work, how isn't it working?
 
Upvote 0
It just flashes on the screen. I think it reopens the workbook and then closes it, but the original file is still open. I opened it in another procedure modified it and then import the file to access. This all work fine. But once that is finished I wanted to close the workbook without saving it.
But all the code I look at looks like the one I have.
Thanks for looking at it with me

Liz
 
Upvote 0
When are you actually opening the workbook and what are you doing when you open it?
 
Upvote 0
I open it up with another sub procedure in Access very similar to the one above, it opens up the workbook and deletes the first 4 rows and the last row. Then I run a query in access that imports the workbook to a temp table and then a second query that appends it to my table. Then I wanted to close the excel file without saving the changes. I all work fine until I run the close sub.

Liz
 
Upvote 0
Liz

Can't you close the file in the sub that opens it?
 
Upvote 0
I could give it a go and see what happens. Thanks Ill let you know tomorrow if it works

Liz
 
Upvote 0
Thanks for your help Norie, having it all in the same sub procedure work
Liz
 
Upvote 0

Forum statistics

Threads
1,221,876
Messages
6,162,567
Members
451,775
Latest member
Aiden Jenner

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