+ Reply to Thread
Results 1 to 14 of 14

Dates not being read correctly

  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?

    Please Login or Register  to view this content.
    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

    Please Login or Register  to view this content.

  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
    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...

    Please Login or Register  to view this content.

  6. #6
    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

  7. #7
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,557

    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 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    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 rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    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.
    Rory

  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. 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