+ Reply to Thread
Results 1 to 14 of 14

Dates not being read correctly

Hybrid View

Chameleon5669 Dates not being read correctly 08-09-2023, 06:43 PM
Lastejp Re: Dates not being read... 08-10-2023, 09:11 AM
Chameleon5669 Re: Dates not being read... 08-10-2023, 09:39 AM
Lastejp Re: Dates not being read... 08-10-2023, 11:30 AM
Chameleon5669 Re: Dates not being read... 08-11-2023, 01:37 PM
Lastejp Re: Dates not being read... 08-10-2023, 04:56 PM
JeteMc Re: Dates not being read... 08-13-2023, 09:10 AM
Chameleon5669 Re: Dates not being read... 08-13-2023, 03:05 PM
alansidman Re: Dates not being read... 08-13-2023, 04:42 PM
Lastejp Re: Dates not being read... 08-14-2023, 11:51 AM
Chameleon5669 Re: Dates not being read... 08-14-2023, 04:56 PM
Lastejp Re: Dates not being read... 08-14-2023, 06:17 PM
romperstomper Re: Dates not being read... 08-17-2023, 07:57 AM
Chameleon5669 Re: Dates not being read... 08-17-2023, 03:55 PM
  1. #1
    Registered User
    Join Date
    08-09-2023
    Location
    London
    MS-Off Ver
    o365
    Posts
    6

    Dates not being read correctly

    Hi.

    I have code that used to work on previous versions of Office but doesn't seem to now and I can't work out why.

    I have a spreadsheet with various columns, one of which is dates, formatted as dates (Long Date specifically), then a macro that reads each line and creates a recurring outlook appointment for each one. However, the result is all the details are correct on the Outlook appointment, except it's creating them all today (whichever day you run it). The portion of code that is not quite working is below. It's the Start and End parameters that are just being ignored or overridden.

    Is anyone able to shed any light please?

        With olAppt
            Set oPat = .GetRecurrencePattern
            oPat.RecurrenceType = olRecursYearly
            .Start = DateValue(Cells(i, 3)) + TimeValue("9:00:00")
            .End = DateValue(Cells(i, 3)) + TimeValue("9:01:00")
            .Subject = Cells(i, 1) + " " + Cells(i, 2) + " is on " & Cells(i, 3) & " since " & Cells(i, 4)
            '.Location = Cells(i, 2)
            .Body = .Subject
            .BusyStatus = olFree
            .ReminderMinutesBeforeStart = 10080
            .ReminderSet = True
            '.Categories = Cells(i, 4)
            '.IsRecurring
            .Save
        End With
    Last edited by AliGW; 08-10-2023 at 12:37 AM. Reason: Code tags added - please review the forum rules.

  2. #2
    Registered User
    Join Date
    07-26-2023
    Location
    Oklahoma
    MS-Off Ver
    365
    Posts
    57

    Re: Dates not being read correctly

    Try

    VBA.CDate(Cells(1, 3).Value)

  3. #3
    Registered User
    Join Date
    08-09-2023
    Location
    London
    MS-Off Ver
    o365
    Posts
    6

    Re: Dates not being read correctly

    Nope, makes no difference.

  4. #4
    Registered User
    Join Date
    07-26-2023
    Location
    Oklahoma
    MS-Off Ver
    365
    Posts
    57

    Re: Dates not being read correctly

    What is actually in cell(1,3)?

  5. #5
    Registered User
    Join Date
    08-09-2023
    Location
    London
    MS-Off Ver
    o365
    Posts
    6

    Re: Dates not being read correctly

    Quote Originally Posted by Lastejp View Post
    What is actually in cell(1,3)?
    Here's a screen grab. As I said originally, it's a date field set and formatted as a date field.

    Attachment 839271

  6. #6
    Registered User
    Join Date
    07-26-2023
    Location
    Oklahoma
    MS-Off Ver
    365
    Posts
    57

    Re: Dates not being read correctly

    Try throwing in a DoEvents command after the save...

    With olAppt
            Set oPat = .GetRecurrencePattern
            oPat.RecurrenceType = olRecursYearly
            .Start = DateValue(Cells(i, 3)) + TimeValue("9:00:00")
            .End = DateValue(Cells(i, 3)) + TimeValue("9:01:00")
            .Subject = Cells(i, 1) + " " + Cells(i, 2) + " is on " & Cells(i, 3) & " since " & Cells(i, 4)
            '.Location = Cells(i, 2)
            .Body = .Subject
            .BusyStatus = olFree
            .ReminderMinutesBeforeStart = 10080
            .ReminderSet = True
            '.Categories = Cells(i, 4)
            '.IsRecurring
            .Save
           DoEvents
        End With

  7. #7
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,825

    Re: Dates not being read correctly

    Selecting attachment 839271 results in the following: "Invalid Attachment specified. If you followed a valid link, please notify the administrator"
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  8. #8
    Registered User
    Join Date
    08-09-2023
    Location
    London
    MS-Off Ver
    o365
    Posts
    6

    Re: Dates not being read correctly

    Quote Originally Posted by JeteMc View Post
    Selecting attachment 839271 results in the following: "Invalid Attachment specified. If you followed a valid link, please notify the administrator"
    Trying again. The attach picture thing seems pretty lame on this site.

    Excel Dates Grab.PNG

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,683

    Re: Dates not being read correctly

    @Chameleon5669
    You are right about the add picture Icon. It does not work. Instead use the procedure in the yellow banner at the top of this page to attach either a screen shot or a file in the future and you will not have any issues.

    Alan
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  10. #10
    Registered User
    Join Date
    07-26-2023
    Location
    Oklahoma
    MS-Off Ver
    365
    Posts
    57

    Re: Dates not being read correctly

    I see the problem. When you format a date such as 26 November 2017, it is not interpreted as a date when read back in. Change that format to something like mm/dd/yyyy and it should work

  11. #11
    Registered User
    Join Date
    08-09-2023
    Location
    London
    MS-Off Ver
    o365
    Posts
    6

    Re: Dates not being read correctly

    Quote Originally Posted by Lastejp View Post
    I see the problem. When you format a date such as 26 November 2017, it is not interpreted as a date when read back in. Change that format to something like mm/dd/yyyy and it should work
    Actually, no it isn't. Excel does store the date as a date serial if you select the "Date" dropdown, the purpose of that dropdown is just to describe how you want it visually represented. So, in theory, you SHOULDN'T need to use DateValue(cells(i,3) or Format(Cells(i, 3), "yyyy-mm-dd") & " 9:00:00 AM" because it is ALREADY a date, and Outlook is EXPECTING a DateTime. However, notwithstanding all that, I have tried both of those and neither makes a blind bit of difference to the outcome.

    The real question here is What has changed in the Outlook/Excel/Office object model since version 16 that has broken this, as it was working fine in all previous versions of Office?

    I'm of course grateful for people guessing or issuing conjecture, but what's needed here is an actual Microsoft MVP VBA programmer to actually answer the questions! I've helpfully attached a screen grab showing the cells correctly formatted as Dates and...showing Dates...

  12. #12
    Registered User
    Join Date
    07-26-2023
    Location
    Oklahoma
    MS-Off Ver
    365
    Posts
    57

    Re: Dates not being read correctly

    You're right. It's only if you format the day such as "Friday August 18 2023" that doesn't read back in.

    Did you try what I suggested earlier?

    Throw in a DoEvents command after the save

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,968

    Re: Dates not being read correctly

    Your code works fine here with 365, with or without DateValue.

    The only way I can see that you would get today's date for the appointment is if you have an On Error Resume Next suppressing errors and whatever value is in column C for that row does not convert to a date.
    Everyone who confuses correlation and causation ends up dead.

  14. #14
    Registered User
    Join Date
    08-09-2023
    Location
    London
    MS-Off Ver
    o365
    Posts
    6

    Re: Dates not being read correctly

    For info: So, after a simply ENORMOUS amount of phaffing. The solution is to move the Recurrence get/set after the setting of the .Start and .End parameters. Why that is, god knows. But that solves it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Unable to read a number. All text is reading correctly
    By JChandler8314 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-29-2020, 07:10 AM
  2. [SOLVED] VBA not filtering dates correctly
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-15-2019, 12:59 AM
  3. Convert European dates to Excel-read dates
    By thepinkgeologist in forum Excel General
    Replies: 1
    Last Post: 09-21-2015, 10:33 AM
  4. Replies: 11
    Last Post: 07-05-2015, 12:46 PM
  5. [SOLVED] Excel 2007 : 2007 Files, not being read correctly by 2010
    By simon@natsow.co.za in forum Excel General
    Replies: 1
    Last Post: 04-11-2012, 11:00 AM
  6. Dates not formatting correctly
    By calsonicgtr in forum Excel General
    Replies: 1
    Last Post: 08-22-2011, 12:44 PM
  7. Read clipboard doesn't work correctly
    By marmotinchen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2011, 08:16 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1