dm83737 Posted March 17, 2009 Share Posted March 17, 2009 I am reading a cell from Excel for the date of birth for clients that gets entered into another application; this date reads as 07041959 within Excel (formatted as this custom setting for the cells = mmddyyyy). When AutoIT gets to the point of entering that cell's contents to the other application, it inputs 19590704 (yyyymmdd). I have tried changing the custom cell setup to yyyymmdd to see if maybe it would read it backwards and therefore correct itself, but it once again entered 19590704. So now I am thinking it has something to do with the fact that the cell is of the Date type and that somehow makes AutoIT behave a certain way. So I am hoping there is a way to override this and get it to enter the date as 07041959. My last option would be to have those cells be formatted as text, but that forfeits other functionality I have on this spreadsheet that depends on those dates. I am pretty sure this is another easy one that I just cant seem to put my finger on, so I know there will be a quick resolution from one of the wise ones around here. I have attached a picture to illustrate what I am talking about. This is the pieces of code I am using. As you can see, there is nothing special about them. For $iRowRange = 2 To 999 $iDOB = _ExcelReadCell($oExcel, $iRowRange, 4) ... Send($iDOB) * Obviously much more code within the script that is not relevant here Link to comment Share on other sites More sharing options...
erik7426 Posted March 17, 2009 Share Posted March 17, 2009 I am reading a cell from Excel for the date of birth for clients that gets entered into another application; this date reads as 07041959 within Excel (formatted as this custom setting for the cells = mmddyyyy). When AutoIT gets to the point of entering that cell's contents to the other application, it inputs 19590704 (yyyymmdd). I have tried changing the custom cell setup to yyyymmdd to see if maybe it would read it backwards and therefore correct itself, but it once again entered 19590704. So now I am thinking it has something to do with the fact that the cell is of the Date type and that somehow makes AutoIT behave a certain way. So I am hoping there is a way to override this and get it to enter the date as 07041959. My last option would be to have those cells be formatted as text, but that forfeits other functionality I have on this spreadsheet that depends on those dates. I am pretty sure this is another easy one that I just cant seem to put my finger on, so I know there will be a quick resolution from one of the wise ones around here. I have attached a picture to illustrate what I am talking about. This is the pieces of code I am using. As you can see, there is nothing special about them. For $iRowRange = 2 To 999 $iDOB = _ExcelReadCell($oExcel, $iRowRange, 4) ... Send($iDOB) * Obviously much more code within the script that is not relevant here I can't recreate your problem. In fact, I am having trouble formatting an excel field as you have. I did create an excel file and put dates in column D such as 07041959 and 05111975 and when using this code: #include <Excel.au3> $sFilePath1 = @ScriptDir & "\Test1.xls";This file should already exist $oExcel = _ExcelBookOpen($sFilePath1) For $iRowRange = 2 To 999 $iDOB = _ExcelReadCell($oExcel, $iRowRange, 4) If $iDOB <> "" Then MsgBox(0, "", $iDOB) EndIf Next _ExcelBookClose($oExcel, 1, 0) I get the date returned in the message box exactly as it has been put in Excel. Perhaps if you could post more code or perhaps a sample of part of your Excel file?? Link to comment Share on other sites More sharing options...
Bowmore Posted March 17, 2009 Share Posted March 17, 2009 Try this slightly modified version of _ExcelReadCell(). It should return the contents of the cell as it appears in Excel rather than the underlying value Func _ExcelReadCell($oExcel, $sRangeOrRow, $iColumn = 1) If Not IsObj($oExcel) Then Return SetError(1, 0, 0) If Not StringRegExp($sRangeOrRow, "[A-Z,a-z]", 0) Then If $sRangeOrRow < 1 Then Return SetError(2, 0, 0) If $iColumn < 1 Then Return SetError(2, 1, 0) Return $oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Text Else Return $oExcel.Activesheet.Range($sRangeOrRow).Text EndIf EndFunc ;==>_ExcelReadCell "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
TimCunningham Posted March 18, 2013 Share Posted March 18, 2013 This fixed my issue that I was having. Thanks for the code. Try this slightly modified version of _ExcelReadCell(). It should return the contents of the cell as it appears in Excel rather than the underlying value Func _ExcelReadCell($oExcel, $sRangeOrRow, $iColumn = 1) If Not IsObj($oExcel) Then Return SetError(1, 0, 0) If Not StringRegExp($sRangeOrRow, "[A-Z,a-z]", 0) Then If $sRangeOrRow < 1 Then Return SetError(2, 0, 0) If $iColumn < 1 Then Return SetError(2, 1, 0) Return $oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Text Else Return $oExcel.Activesheet.Range($sRangeOrRow).Text EndIf EndFunc ;==>_ExcelReadCell Link to comment Share on other sites More sharing options...
water Posted March 18, 2013 Share Posted March 18, 2013 This thread is 4 years old. Isn't it a bit late? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now