Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

opening prior month file

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Opening Prior Month File

Opening Prior Month File

ResolvedVersion 2010

Freddie has attended:
Excel VBA Introduction course

Opening Prior Month File

Hi Guys


I seemed to have encountered a problem with the below:

FileYear = Year(Date)
strFileMonth = Format(DateAdd("m", -1, Now), "YYYYMM")
FileDate = Format(Date - 1, "dd.mm.yyyy")
Filepath = "L:\ClientInterest\CI shared\~ Month End Interest Process ~\3) LDN\LDN Month End\" & FileYear & "\" & strFileMonth & "\*DUMMY*.xlsx"

Workbooks.Open (Filepath)
ActiveWorkbook.SaveAs "C:\Users\richard.heron\Desktop\KPI\Latest KPI FILE.xlsx"
Application.DisplayAlerts = False

It seems when we approach January - it won't go back and look in 2015 for December's file.

The issue stems around the Year(Date). Is there an IF function I can apply to this?

Any help would be greatly appreciated!

Tks

Freddie

RE: Opening Prior Month File

Hi Freddy,


Thank you for the forum question.

Try with a IF DECISION code:


If month(date)=1 then

FileYear = Year(Date)-1
strFileMonth = Format(DateAdd("m", -1, Now), "YYYYMM")
FileDate = Format(Date - 1, "dd.mm.yyyy")
Filepath = "L:\ClientInterest\CI shared\~ Month End Interest Process ~\3) LDN\LDN Month End\" & FileYear & "\" & strFileMonth & "\*DUMMY*.xlsx"

Else

FileYear = Year(Date)
strFileMonth = Format(DateAdd("m", -1, Now), "YYYYMM")
FileDate = Format(Date - 1, "dd.mm.yyyy")
Filepath = "L:\ClientInterest\CI shared\~ Month End Interest Process ~\3) LDN\LDN Month End\" & FileYear & "\" & strFileMonth & "\*DUMMY*.xlsx"

End If

Workbooks.Open (Filepath)
ActiveWorkbook.SaveAs "C:\Users\richard.heron\Desktop\KPI\Latest KPI FILE.xlsx"
Application.DisplayAlerts = False



What I am doing: If the month is month one I subtract one from the year.

I hope this can help you.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Wed 27 Jan 2016: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Quickly create a list of numbers

The fill handle in Excel has many uses. If a number is typed into a cell and then the fill handle is used, the number will be copied from one cell to the next.

If you wish to create a list of numbers that increment by one at a time, hold down Ctrl in conjunction with using the fill handle - this should give you a series of numbers (e.g. 1, 2, 3 etc) rather than copying a single number.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.