Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 68
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,393
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date not defaulting to current year Tim Elhatton Excel Worksheet Functions 4 November 16th 07 10:33 PM
Combination Graph with current year and prior year sales JanW Charts and Charting in Excel 2 April 5th 07 09:20 PM
days since 1/1/current year dan Excel Discussion (Misc queries) 6 October 14th 06 07:20 PM
Current year function Sam at JWP Excel Worksheet Functions 1 July 1st 05 05:33 AM
How to compare current year to prior year in bar chart? substring Charts and Charting in Excel 4 May 12th 05 07:04 PM


All times are GMT +1. The time now is 01:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"