ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Close current workbook (https://www.excelbanter.com/excel-programming/437783-close-current-workbook.html)

Robert Crandal

Close current workbook
 
I need some VBA code to tell my current workbook
to close itself. The problem is, my workbook will not
always have the same filename. Users may change the
names of their workbook files at any time, so I need
a way to close a workbook without referencing the
filename associated with a workbook.

Is this possible?

thank you



joel[_401_]

Close current workbook
 

The workbook with the macro is refered to as THISWORKBOOK. So you can
use

Thisworkbook.close savechanges:=True
or
Thisworkbook.close savechanges:=True


This will leave the excel application running

To close the application and the workbook first save the file then quit
the application


Thisworkbook.Save
Thisworkbook.quit


You can't close the application if you son't want to save the file.


If you are referencing another workbook I always recommend giving all
workbook a variable name on opening.


set bk = workbooks.open(filename:="book1.xls")

The using bk to close the workbooks

bk.save
bk.close savechanges:=true
thisworkbook.quit


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=165091

Microsoft Office Help


Barb Reinhardt

Close current workbook
 
Joel,

If you use

ThisWorkbook.close

that would end execution of all macros in "ThisWorkbook."

Barb Reinhardt



"joel" wrote:


The workbook with the macro is refered to as THISWORKBOOK. So you can
use

Thisworkbook.close savechanges:=True
or
Thisworkbook.close savechanges:=True


This will leave the excel application running

To close the application and the workbook first save the file then quit
the application


Thisworkbook.Save
Thisworkbook.quit


You can't close the application if you son't want to save the file.


If you are referencing another workbook I always recommend giving all
workbook a variable name on opening.


set bk = workbooks.open(filename:="book1.xls")

The using bk to close the workbooks

bk.save
bk.close savechanges:=true
thisworkbook.quit


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=165091

Microsoft Office Help

.



All times are GMT +1. The time now is 05:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com