VBA-OnOpen search for the newest file and append

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
Hi there,

We have a few daily system generated reports that are dropped into files on the network. these files are labeled "ASD_2011/1/23", "ASD_2010/1/23" etc.

I need a Macro or VBA that runs on open and gets Todays data and then appends it to the current database. however this file may be opened a few times a day, so it needs to be able to workout if it has already collected the data.

Currently I amend the file name every morning and then run this macro.

Code:
ChDir "C:\Users\user\Documents\Excel files"
    Workbooks.Open Filename:= _
        "C:\Users\user\Documents\Excel files\ASD_2011/1/23.xlsx"
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Windows("MasterStartsReport.xlsx").Activate
    ActiveSheet.Paste
    Windows("ASD_2011/1/23.xlsx").Activate
    ActiveWindow.Close

As you can see this is not the nbst way to do this.

can someone assist?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,216,080
Messages
6,128,692
Members
449,464
Latest member
againofsoul

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