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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.