Open File Using Macro

Please assist with this code. I am trying to record a macro to open file using filename that changes with date changes.

Sub CopyPriorBalance()
'
' CopyPriorBalance Macro
'
 Filepath = ("PriorFile")
 Filename = ("PriorFilename")
 Tabname = ("Daily, MTD, YTD")
 
 Workbooks.Open Filename:=Filename
 
 Sheets("Daily, MTD, YTD").Select
 Range("J41").Select
 Range("I79:M79").Select
 Selection.Copy
 Windows("Bonds and Derivatives Flow PL Template.xlsm").Activate
 Range("I100").Select
 Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
'
End Sub
IbukunkapitalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
I'm not sure about how you define the file name as from the code you pasted it's not clear..

However in macro you can use the function of now() which basically gives you system date and time...

Now assuming you want to open a filename of yesterdaydate and save as like abc_03102015.xlsx

you can do this..

filename="abc_" & format(now()-1,"mmddyyyy") & ".xlsx"

Open in new window


This will automatically change basis of your system date when the time gets changed...

Saurabh...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IbukunkapitalAuthor Commented:
Could you assist with code that can open a file in a folder and the difference between the file names is the date at the back of the file names.

For example, the folder contains:

Ibukun_10.03.2015
Ibukun_11.03.2015
0
Saurabh Singh TeotiaCommented:
This will become then...

for 10th mar...
filename="ibukun_" & format(now()-2,"dd.mm.yyyy") & ".xlsx"

for 11th mar...
filename="ibukun_" & format(now()-1,"dd.mm.yyyy") & ".xlsx"

Open in new window

0
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.