use current year in macro

M

mohavv

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
 
B

Bernard Liengme

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
 

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