+ Reply to Thread
Results 1 to 9 of 9

Date Format Changes US vs. EU

Hybrid View

  1. #1
    Registered User
    Join Date
    01-24-2012
    Location
    netherlands
    MS-Off Ver
    Excel 2007
    Posts
    4

    Date Format Changes US vs. EU

    Hi all,

    I have a problem.
    Ive Created a script witch simply copy's a mail to Excel but these mails contain date's.
    The normal format of my pc = "d/m/yyyy" (regional and language settings)
    My Excel format again = "d/m/yyyy"
    My Office i maight add is English US (maybe this is the problem)
    And still when i run the script excel just converts it to "m/d/yyyy".
    In excel there is some code that adds days to the date so i need the date setting else i just format the cells to "text".

    Ive looked at almost every site listed in google about this problem but i cant seem to find a real solution just work arounds that dont aply.

    Thnx in advance

  2. #2
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Date Format Changes US vs. EU

    Whenm you transfer a string 'date' to an Excel cell, use DateValue to convert to a proper numeric date according to your Regional Settings so:

    Range("A1").Value = DateValue(strMyDate)

  3. #3
    Registered User
    Join Date
    01-24-2012
    Location
    netherlands
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Date Format Changes US vs. EU

    Thanks,

    Well the problem is that the origional tekst is from a mail so its not formated and it always changes so there's no way for me to format it in the text.
    The text from the mail gets copied to Clipboard and then gets pasted in to excel.
    Then the date changed from d/m/yyyy to m/d/yyyy dispite the fact that excel thinks the cell is still formated d/m/yyyy

    The cell where the date is goin to be stated in is variable
    Last edited by Bochelair; 02-07-2012 at 06:49 AM.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Date Format Changes US vs. EU

    post the code
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    01-24-2012
    Location
    netherlands
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Date Format Changes US vs. EU

    PHP Code: 
    Sub OpenMailinExcel()
    Dim myitem As Object
    Dim myOlApp 
    As New Outlook.Application
    Dim myOlExp 
    As Outlook.Explorer
    Dim myOlSel 
    As Outlook.Selection
    Dim MyData 
    As DataObject
    Set MyData 
    = New DataObject
    Set myOlExp 
    myOlApp.ActiveExplorer
    Set myOlSel 
    myOlExp.Selection
    For Each myitem In myOlSel
        MyData
    .SetText myitem.Body
        MyData
    .PutInClipboard
        Dim xlApp 
    As Object
        Dim xlWkb 
    As Object
        Set xlApp 
    CreateObject("Excel.Application")
        
    xlApp.Visible True

        xlApp
    .Workbooks.Open FileName:="C:\Documents and Settings\js0000283\My Documents\m4u factuur.xlsm", ReadOnly:=True
        
        xlApp
    .Worksheets("Mail").Select
        xlApp
    .Range("A1").Select
        xlApp
    .Activesheet.Paste
    Next
    End Sub 
    This is in outlook

  6. #6
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Date Format Changes US vs. EU

    Is the information you are extracting from Outlook just dates or do you extract other information too (whether numeric values, words or whatever)?

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Date Format Changes US vs. EU

    Please use Code Tags not PHP tags

  8. #8
    Registered User
    Join Date
    01-24-2012
    Location
    netherlands
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Date Format Changes US vs. EU

    Just 1 date but there's more tekst

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Date Format Changes US vs. EU

    Sub OpenMailinExcel() 
     for each it in getnamespace("MAPI").ActiveExplorer.selection
      c01=c01 & "|" & it.body
     next
    
     sn=split(mid(c01,2),"|")
     with getobject("C:\Documents and Settings\js0000283\My Documents\m4u factuur.xlsm") 
      for j=0 to ubound(sn)
       .sheets("Mail").cells(j+1,1)=datevalue(sn(j))
      next
     end with
    End Sub
    I assume you are running the code from Outlook.

    If you are interested in the combination VBA-Outlook have a look over here.
    Last edited by snb; 02-07-2012 at 08:41 AM.



+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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