Update to Excel 2013 - Broken VBA

jimmisavage

Board Regular
Joined
Jun 28, 2017
Messages
130
Hi,
I hope someone can help. I run a vba which sends email reminders when a date is approaching. This used to work a dream in Excel 2007 but work have upgraded to 2013 and now the VBA stops in it's tracks - It seems to highlight the word 'Date' on the IF statement:
If sDate <= Date - 14 Then
Ws.Cells(i, 5).ClearContents
Ws.Cells(i, 8).ClearContents
End If

The error is: Compile error: Can't find project or library

VBA Code:
ActiveWorkbook.Sheets("Home").Activate
Dim lRow As Integer
Dim i As Integer
Dim toDate As Date
Dim toList As String
Dim eSubject As String
Dim eBody As String
With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .DisplayAlerts = False
End With
Sheets("mailpage").Visible = True
Sheets("mailpage").Select

Dim Ws As Worksheet
Dim LR As Long
Dim sDate As Date, fDate As Date
Application.ScreenUpdating = False
Set Ws = Worksheets("mailpage")
LR = Ws.Range("H" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    sDate = Ws.Cells(i, 8).Value
    If sDate <= Date - 14 Then
        Ws.Cells(i, 5).ClearContents
        Ws.Cells(i, 8).ClearContents
    End If
Next i
Application.ScreenUpdating = True
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Check the references in the project (Tools - References in the VB Editor). One (or more) of them will be flagged as 'MISSING:'
 
Upvote 0
Check the references in the project (Tools - References in the VB Editor). One (or more) of them will be flagged as 'MISSING:'

Hi RoryA, thanks for the quick reply!
I have tried that but i'm getting another error: Error accessing the system registry. :(
 
Upvote 0
Did you stop the running code first? If so, I think a repair of the Office installation may be needed.
 
Upvote 0
Did you stop the running code first? If so, I think a repair of the Office installation may be needed.
Thanks Rory, I finally got around to sorting this. My work IT tried a repair install but the problem didn't go away. In the end i simply copied the code, saved to worksheet as a .xlsx, reopened, pasted the code back in and saved as .xlsm again - it works again now :)
 
Last edited:
Upvote 0
You can't have code in a workbook saved as xlsx format, so I'm confused.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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