[HELP] Macro to switch between workbook with date on its name

sabatine

New Member
Joined
May 30, 2012
Messages
3
Hello!

I need to create a macro that updates some datas for me, but I am having some troubles switching workbooks.

I need to activate a workbook that has the date of the yesterday on it's name.

i.e: a have an workbook that is updated everyday, so it's name is Open PO_yyyymmdd.

This macro will open this workbook (which is the one that I need to update data) and two others.

After it opens these workbooks, I need it to activate the one named Open PO_yyyymmdd.

Does anyone knows if it's possible to do so?

Here is the part of the code that I need help (specifically the last line of code):

Workbooks.Open Filename:="C:\Users\Felipe\Desktop\Open PO_XXX" & Format(Date, "yyyymmdd")
Workbooks.Open Filename:="C:\Users\Felipe\Desktop\POs_With_Cost"
Workbooks.Open Filename:="C:\Users\Felipe\Desktop\Macro"
Workbooks("Open PO_XXX ").Activate

Can anyone help me, please?

Thanks in advance.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You need the full name of the workbook including the file extension:
Rich (BB code):
Workbooks("Open PO_yyyymmdd.xls").Activate
change the file extension to match your workbook.
 
Upvote 0
I appreciate your answer, but it's not that what I need.

I need a formula that alternate between open workbooks.

though, one these workbooks has on it filename a formula that saves him with today's date.

i.e.: Workbooks.Open Filename:="C:\Users\Felipe\Desktop\Open PO_XXX" & Format(Date, "yyyymmdd")

This formula will open the workbook that has the prefix Open PO_XXX and also has the current day date.

I need a formula that alternates between another workbook and this one.

Reminding that I will use this macro everyday, so workbook name will change accordingly to the date of the day. Because of this, I cannot ask macro to alternate to a file that has a fixed date, because it won't be right for what I need to do.

Do you know how to do that? Someone? Help!

Tks! :)
 
Upvote 0
Hello Sabatine,

When working with multiple workbooks, it is a good practice to a assign each workbook that is opened to a unique object variable. This will allow you to easily access each one. As JoeMo pointed out you also need to include the file type extension when opening the file.
Code:
Dim Wkb1 As Workbook
Dim Wkb2 As Workbook
Dim Wkb3 As Workbook

    Set Wkb1 = Workbooks.Open(Filename:="C:\Users\Felipe\Desktop\Open PO_XXX" & Format(Date, "yyyymmdd") & ".xls")
    Set Wkb2 = Workbooks.Open(Filename:="C:\Users\Felipe\Desktop\POs_With_Cost.xls")
    Set Wkb3 = Workbooks.Open(Filename:="C:\Users\Felipe\Desktop\Macro.xls")

    Wkb1.Activate
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top