Run Macro on Open and If statement

BYUIStudent

New Member
Joined
Jun 25, 2015
Messages
10
Hello everyone, Thank you in advanced for your help.

I would like to have a macro run when a workbook is opened but only if the current date of a cell doesn't match up with the system date.

What I have
Private Sub Auto_Open()


Application.ScreenUpdating = False
ActiveWorkbook.Connections("Query - Table1").Refresh
ActiveWorkbook.Connections("Query - Table2").Refresh
Application.ScreenUpdating = True
ActiveWorkbook.Save


End Sub

What I would like it to do is

If cell b3 in Sheet 3 = today's date then run above macro.

any help would be great thank you.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hello,

Place this on the ThisWorkbook Module (ALT+F11, look top right in the project window)

Code:
Private Sub Workbook_Open()
    If Sheets("Sheet3").Range("B3").Value = Date Then
        Application.ScreenUpdating = False
        With ActiveWorkbook
            .Connections("Query - Table1").Refresh
            .Connections("Query - Table2").Refresh
            .Save
        End With
        Application.ScreenUpdating = True
    End If
End Sub

Let me know if it works
Cheers
Caleeco
 
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,652
Members
449,245
Latest member
PatrickL

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