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

resolvedResolved · High Priority · Version 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:

Repeating headings on spreadsheets that print on more than one page

By default when you print a spreadsheet out and it prints on more than one page, the headings at the top and the side of the spreadsheet don't appear on all the pages following page 1.

To get Excel to repeat headings on all pages when printing, go to File - Page Setup - Sheet, then select the rows to repeat at the top of pages, and the columns to repeat at the side of pages by clicking on the red arrows at the right side of the two boxes under the 'Print titles' area. Then click OK.

If you view your spreadsheet in Print Preview, you should see the headings being repeated on each page.

View all Excel hints and tips


Server loaded in 0.05 secs.