ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   use current year in macro (https://www.excelbanter.com/excel-discussion-misc-queries/172162-use-current-year-macro.html)

mohavv

use current year in macro
 
Is there a way to use the current year in a a macro?

I have the following code (partially):

Set wkbk = Nothing
On Error Resume Next
Set wkbk=Workbooks("08Bud 0770.xls")
On Error GoTo 0

If wkbk = Nothing then

Set wkbk = Workbooks.Open(Filename:"=P:\Excel\2008\08Bud 0770.xls"

etc

This repeats several times for different files

Now I want to copy the file for budget 2009 and all other sub files,
changing only the year number.

I want, without somebody opening VBE, the macro to work in the new
file to.

Any suggestions?

Cheers,

Harold

Bernard Liengme

use current year in macro
 
Use the Date and Year VBA functions, as in:
Sub showyear()
myYear = Year(Date)
MsgBox myYear
End Sub

Of course, for 2009 this year you could use:
myYear = Year(Date) +1
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
www.stfx.ca/people/bliengme
remove caps from email

"mohavv" wrote in message
...
Is there a way to use the current year in a a macro?

I have the following code (partially):

Set wkbk = Nothing
On Error Resume Next
Set wkbk=Workbooks("08Bud 0770.xls")
On Error GoTo 0

If wkbk = Nothing then

Set wkbk = Workbooks.Open(Filename:"=P:\Excel\2008\08Bud 0770.xls"

etc

This repeats several times for different files

Now I want to copy the file for budget 2009 and all other sub files,
changing only the year number.

I want, without somebody opening VBE, the macro to work in the new
file to.

Any suggestions?

Cheers,

Harold





All times are GMT +1. The time now is 02:07 AM.

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