ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Closing a possible Workbook (https://www.excelbanter.com/excel-programming/366891-closing-possible-workbook.html)

Kyle

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

Tom Ogilvy

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


Tom Ogilvy

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



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

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