ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Date to close file (https://www.excelbanter.com/excel-worksheet-functions/248994-date-close-file.html)

PSM[_20_]

Date to close file
 

I'm using the date code below to close the file but just figured that if
the file is renamed this will fail. Is there code that will close the
workbook no matter what the filename to overcome this ?


Dim exdate As Date
exdate = "07/12/2009"
If Date exdate Then
MsgBox ("Sorry this spreadsheet has expired please use latest
version")
Application.DisplayAlerts = False
Workbooks("Master 09 17.50 VAT.XLS").Close
Exit Sub
End If




--
PSM

ddibble

It might help to name the workbook when it is opened and then use that variable when closing. Something like this in your code:


dim wrkNewWorkbook as Workbook

'after you open workbook

wrkNewWorkbook = Activeworkbook.Name

'then after you've done whatever you need to do with the file you can close it

Workbooks(wrkNewWorkbook).Close Savechanges:=false

Or you can just use:

Activeworkbook.Close Savechanges:=false

maybe?



Quote:

Originally Posted by PSM[_20_] (Post 902734)
I'm using the date code below to close the file but just figured that if
the file is renamed this will fail. Is there code that will close the
workbook no matter what the filename to overcome this ?


Dim exdate As Date
exdate = "07/12/2009"
If Date exdate Then
MsgBox ("Sorry this spreadsheet has expired please use latest
version")
Application.DisplayAlerts = False
Workbooks("Master 09 17.50 VAT.XLS").Close
Exit Sub
End If




--
PSM


PSM[_21_]

Date to close file
 

Thanks ddibble, works a treat.

'ddibble[_3_ Wrote:
;3558640']It might help to name the workbook when it is opened and then
use that
variable when closing. Something like this in your code:


dim wrkNewWorkbook as Workbook

'after you open workbook

wrkNewWorkbook = Activeworkbook.Name

'then after you've done whatever you need to do with the file you can
close it

Workbooks(wrkNewWorkbook).Close Savechanges:=false

Or you can just use:

Activeworkbook.Close Savechanges:=false

maybe?



'PSM[_20_ Wrote: -
;902734']I'm using the date code below to close the file but just
figured that if
the file is renamed this will fail. Is there code that will close the
workbook no matter what the filename to overcome this ?


Dim exdate As Date
exdate = "07/12/2009"
If Date exdate Then
MsgBox ("Sorry this spreadsheet has expired please use latest
version")
Application.DisplayAlerts = False
Workbooks("Master 09 17.50 VAT.XLS").Close
Exit Sub
End If




--
PSM-




--
ddibble





--
PSM


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

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