Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Closing a possible Workbook

I have a program that I need to error proof and I want to close a workbook if
its open. I was wondering what my If statement would be if this certain
workbook was open so it would close, otherwise not worry about it.

if ???????????? then
workbooks(wFilename).close
else
endif

Thanks,
Kyle
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Closing a possible Workbook

Dim bk as Workbook
on error resume next
set bk = Workbooks("Mybookname.xls")
On error goto 0
if not bk is nothing then
bk.close Savechanges:=True
End if

--
Regards,
Tom Ogilvy


"kyle" wrote:

I have a program that I need to error proof and I want to close a workbook if
its open. I was wondering what my If statement would be if this certain
workbook was open so it would close, otherwise not worry about it.

if ???????????? then
workbooks(wFilename).close
else
endif

Thanks,
Kyle

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Closing a possible Workbook

didn't see your code, so modify mine to

Dim bk as Workbook
on error resume next
set bk = Workbooks(wFilename)
On error goto 0
if not bk is nothing then
bk.close Savechanges:=True
End if

where wFilename should be myworkbook.xls, not something like
C:\Myfolder\myworkbook.xls


--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote:

Dim bk as Workbook
on error resume next
set bk = Workbooks("Mybookname.xls")
On error goto 0
if not bk is nothing then
bk.close Savechanges:=True
End if

--
Regards,
Tom Ogilvy


"kyle" wrote:

I have a program that I need to error proof and I want to close a workbook if
its open. I was wondering what my If statement would be if this certain
workbook was open so it would close, otherwise not worry about it.

if ???????????? then
workbooks(wFilename).close
else
endif

Thanks,
Kyle

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
Closing Hidden Workbook when Active Workbook is Closed SusanK521 Excel Programming 5 September 24th 05 12:27 AM
Help with closing down a workbook?? Don Excel Worksheet Functions 1 May 9th 05 04:05 AM
Closing a workbook... Jeff Harbin[_2_] Excel Programming 2 August 11th 04 01:52 AM
closing excel after closing a workbook CWalsh[_2_] Excel Programming 3 January 21st 04 03:33 PM
Closing a workbook Belinda Excel Programming 2 January 15th 04 01:27 PM


All times are GMT +1. The time now is 12:55 AM.

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"