Date to close file

P

PSM

I'm using the date code below to close the file but just figured that i
the file is renamed this will fail. Is there code that will close th
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 lates
version")
Application.DisplayAlerts = False
Workbooks("Master 09 17.50 VAT.XLS").Close
Exit Sub
End I
 
S

Simon Lloyd

PSM;564544 said:
I'm using the date code below to close the file but just figured that i
the file is renamed this will fail. Is there code that will close th
workbook no matter what the filename to overcome this

Code
-------------------
Dim exdate As Dat
exdate = "07/12/2009
If Date > exdate The
MsgBox ("Sorry this spreadsheet has expired please use lates
version"
Application.DisplayAlerts = Fals
Workbooks("Master 09 17.50 VAT.XLS").Clos
Exit Su
End I

-------------------


-
PSMIf the code is housed in the personal.xls then simply close th
activeworkbook which should be the "Master....", if the code is house
in the workbook "Master...." then you can close thisworkbook, can yo
give a little more information

--
Simon Lloy

Regards
Simon Lloy
'Microsoft Office Help' (http://www.thecodecage.com
 
D

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?



'PSM[_20_ said:
;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
 
P

PSM

Thanks ddibble, works a treat.

'ddibble[_3_ said:
;3558640']It might help to name the workbook when it is opened and the
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
 

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