Solved

close other workbook - close excel - do not save

Posted on 2014-03-08
5
808 Views
Last Modified: 2014-03-13
We have a data work book that is used to copy data from Access.  

The data is linked to a second workbook
We use VBA code to save the second workbook and break the links to the data work book
We want to close the data workbook without saving, after the code has run

How do I close the Data workbook from within the  code on the second workbook?
I do not want any alerts.
It would also be ok to quit excel with no alerts as the second workbook was saved earlier
0
Comment
Question by:AMixMaster
  • 3
  • 2
5 Comments
 
LVL 81

Assisted Solution

by:byundt
byundt earned 300 total points
ID: 39915417
You might try code like this:
Sub Closeout()
Workbooks("Data.xlsx").Close SaveChanges:=False
Application.DisplayAlerts = False
Application.Quit     'Close Excel and all open workbooks
End Sub

Open in new window

0
 

Author Comment

by:AMixMaster
ID: 39916117
We are on the right track
except when I use Workbooks().Close SaveChanges:=False
it activates the workbook but does not close it and the code does not continue
I should mention that the workbook we are trying to close is an .XLS
0
 

Author Comment

by:AMixMaster
ID: 39916376
0
 

Author Comment

by:AMixMaster
ID: 39928206
I've requested that this question be closed as follows:

Accepted answer: 0 points for AMixMaster's comment #a39916376
Assisted answer: 300 points for byundt's comment #a39915417
Assisted answer: 0 points for AMixMaster's comment #a39916117

for the following reason:

Found the solution on a member website and it worked like a charm :)
0
 
LVL 81

Accepted Solution

by:
byundt earned 300 total points
ID: 39916519
Workbooks.Close doesn't activate a workbook. It closes it. And if the SaveChanges parameter is set to False, then no warning about an unsaved workbook will be displayed.

Workbooks.Close should work with .xls files as well as .xlsx or .xlsm. It has been part of the VBA language since the beginning.

When you run Chip Pearson's code, you will find that Excel remains open. Application.Quit will close all open workbooks and then quit the Excel application. If the workbooks being closed have been changed since they were last saved, you will see a warning message asking whether to save them first. Application.DisplayAlerts = False will suppress those warning messages.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question