Please Help me fix a ‘hopefully’ simple ‘Type Mismatch’

Barkworth

New Member
Joined
May 25, 2020
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
I have a simple macro which essentially checks if the below specified date is the is older than the last modified date of a master file saved in a shared area.

But for some reason when I run it, it get “type mismatch”… but why :(

Might be worth noting I have the exact same code in the ‘This Workbook’ section of the add-in, which runs on ‘Workbook_Open’. Is that an issue?

VBA Code:
Public Sub UpdateCheck(control As IRibbonControl)

 

Dim CurrentVersionDate As Date

CurrentVersionDate = ("18/11/2021") '<---- MUST UPDATE ON DAY OF NEW VERSION RELEASE IN MM/DD/YYY FORMAT

 

Dim LastUpdateDate As Date

LastUpdateDate = Int(FileDateTime("P:\SCG\Macros\CommoditiesSuite.xlam"))

 



If LastUpdateDate > CurrentVersionDate Then

    If MsgBox("Last Updated on: " & CurrentVersionDate & vbNewLine & "Latest Available Version: " & LastUpdateDate & vbNewLine & vbNewLine & "Your CommoditiesSuite version is out of date..." & vbNewLine & "Do you want to update?", vbYesNo, "Version Check") = vbYes Then

        Workbooks.Open ("P:\SCG\Macros\INSTALL.xlsm")

        Else

        Exit Sub

        End If

        

Else

Exit Sub

End If
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
CurrentVersionDate = ("18/11/2021") '<---- MUST UPDATE ON DAY OF NEW VERSION RELEASE IN MM/DD/YYY FORMAT

You cannot force VBA to accept a certain date format. A date in Excel is actually a number. The format of a date is just for displaying purposes. VBA has a CDate function to convert a text string like "11/18/2021" into a date number but that sometimes goes wrong dependent on regional settings. Users sometimes get confused at times they intend to convert a string like "11/4/2021" to the date of November 4th but end up with a date of April 11th.
Would recommend to use the DateSerial function or. That way days and months never get switched unexpectedly.

VBA Code:
CurrentVersionDate = VBA.DateSerial(2021, 11, 18)    ' << fixed order: year, month, day
 
Last edited:
Upvote 0
try using either of the VBA functions

DateValue(Date String) - where Date String is a string that represents a date such as "18/11/2021"

or

DateSerial(Year, Month, Day)


VBA Code:
Dim CurrentVersionDate As Date

CurrentVersionDate = DateValue("18/11/2021")

CurrentVersionDate = DateSerial(2021, 11, 18)

Both functions should return the corresponding Date number

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,047
Members
449,064
Latest member
scottdog129

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