Edit Replace VBA

odonnke

New Member
Joined
Mar 28, 2003
Messages
5
Hello all, could anyone help me with this one, I have a macro that is run daily. the file is dropped down from our server and updated with the new date AR010405.xls The macro is currently edited manually with an edit replace in VB
ie edit replace AR010405.xls to AR010505.xls.

I would like to know a couple things,
1- at the end of the macro I would like this string to be update with the new date ie 010505
2- put this macro on self timer so that it launches every morning after the file is dropped down.
Workbooks.Open Filename:="K:\AR010405.xls"

the macro is in a seperate workbook but same network location
the whole purpose for the macro is to take a raw data file and format it for users

your help would be greatly appreciated!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Welcome to the Board!

You might be able to use something like this to adjust the date/filename:
Code:
Sub Test()
    Dim NewDate As String
        NewDate = Format(Date, "mmddyy")
    
    Workbooks.Open "K:\AR" & NewDate & ".XLS"

End Sub
As for running it automatically, you can put your code in a Workbook_Open event. You can then use the Windows Scheduler to automatically open the workbook at a specified time each day.

Hope that helps,

Smitty
 
Upvote 0
Thanks, would I use the same code to open a file from the day before as well?
ie. I open todays file and yesterdays file and update yesterdays info onto todays file, obviously both dates need to change in the macro.

Workbooks open event, not familiar with this one could you explain?
also do you mean schedule a task?

thanks a bunch
 
Upvote 0
Just add a bit to get yesterday's date:
Code:
Sub Test()
    Dim NewDate As String
    Dim OldDate As String
        NewDate = Format(Date, "mmddyy")
        OldDate = Format(Date - 1, "mmddyy")
    
    Workbooks.Open "K:\AR" & NewDate & ".XLS"
    '   Do something
    Workbooks.Open "K:\AR" & OldDate & ".XLS"
    '   Do something else
End Sub
As for Workbook_Open event, it's invoked whenever you open a workbook. It's a great way to automate certain things. The VBA helpfile documents it pretty well.

As for Schedule, I did meant the Windows Task Scheduler, sorry.

Smitty
 
Upvote 0

Forum statistics

Threads
1,203,483
Messages
6,055,679
Members
444,807
Latest member
RustyExcel

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