Close current workbook

R

Robert Crandal

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
 
J

joel

The workbook with the macro is refered to as THISWORKBOOK. So you ca
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 qui
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 al
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.qui
 
B

Barb Reinhardt

Joel,

If you use

ThisWorkbook.close

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

Barb Reinhardt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top