VBA code to activate file with current date in its name and if not found open, then open it from the location.

aman2059

Board Regular
Joined
Jan 17, 2016
Messages
75
Hi,

I am trying to write one code. In this code, there is one file which I need to activate among the existing open excel files. Also if this file is not found open, I need to open this file from the given location without giving any error(I am not sure how to do this part). The objective is to make the file as active to run further code. Below is the macro code, right now it gives an error.

Please help.

Code:
Sub copytonewjoinertesting()
' to get data in new joiners report
' need to figure how to open file with the date in its name - learner data report

    Dim FName As String
    Dim FPath As String
    Dim wb1 As ThisWorkbook
    Dim wb2 As Workbook
    
    FPath = "C:\Users\aman.bhardwaj\Desktop\Ideas\Learning process\Master files\testing\saved report\"
    FName = "LearnersinMandateDataExport_3657_" & Format(Date, "mmddyyyy") & ".xlsx"


    Workbooks.Open Filename:=FPath & FName
      Set wb1 = ActiveWorkbook
    Workbooks.Open ("C:\Users\aman.bhardwaj\Desktop\Ideas\Learning process\Master files\testing\New Joiners_Exceptions Report.xlsx")
    Set wb2 = ActiveWorkbook
wb1.Sheets("Sheet1").Select
    
    Range("T1").Select
    ActiveSheet.Range(("A1"), Selection.End(xlDown)).AutoFilter Field:=20, Criteria1:="", Operator:=xlAnd
    
    
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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