Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default 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

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close a toolbar on exit of workbook - current code not work Tom Joseph Excel Programming 10 February 23rd 09 01:58 AM
Open New Workbook / Save and Close Current Workbook Joe K. Excel Programming 1 December 7th 07 08:04 PM
File to close itself and the current instance of XL XP Excel Programming 3 March 16th 07 04:54 PM
Close a the current workbook and load another specified workbook Adrian[_7_] Excel Programming 4 August 7th 04 05:29 PM
Close current Workbook after calling macro in other Des Janke Excel Programming 4 August 7th 03 07:33 AM


All times are GMT +1. The time now is 07:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"