Jump to content

latest version of Autoit How to change Excel Number format


Recommended Posts


      I'm trying to figure out how to change the number format in excel using the latest version of Autoit. The old version I used this 

_ExcelNumberFormat($oExcel, "0.00", "E:E")

I didn't see anything in the help file about it and it's not in the change file. I did find this on MSDN but I'm not sure how to use this in my script. 

How can I format my number column in excel like this 25599.00 from this 25599. I think it's something like this. 

$oExcel.NumberFormat($oExcel, "0.00", "E:E")
Link to comment
Share on other sites


      After searching and trying diff method's, this is what worked for me. I copied the function from an older version of Excel.au3 and paste it at the bottom of my script and used the original syntax and it worked. 

BTW: I'm using Excel 2013 and this worked. 

Func _ExcelNumberFormat($oExcel, $sFormat, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
    If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
    If Not StringRegExp($sRangeOrRowStart, "[A-Z,a-z]", 0) Then
        If $sRangeOrRowStart < 1 Then Return SetError(2, 0, 0)
        If $iColStart < 1 Then Return SetError(2, 1, 0)
        If $iRowEnd < $sRangeOrRowStart Then Return SetError(3, 0, 0)
        If $iColEnd < $iColStart Then Return SetError(3, 1, 0)
        With $oExcel.ActiveSheet
            .Range(.Cells($sRangeOrRowStart, $iColStart), .Cells($iRowEnd, $iColEnd)).NumberFormat = $sFormat
        Return 1
        $oExcel.ActiveSheet.Range($sRangeOrRowStart).NumberFormat = $sFormat
        Return 1
EndFunc   ;==>_ExcelNumberFormat
Edited by RickB75
Link to comment
Share on other sites

  • Moderators

I use something like this, personally:

#include <Excel.au3>
$oExcel = _Excel_Open()

$oWorkbook = _Excel_BookOpen($oExcel, @DesktopDir & "\1.xls")
$oWorkbook.ActiveSheet.Range("A1:A20").NumberFormat = "hh:mm:ss"
$oWorkbook.ActiveSheet.Range("B1:B20").NumberFormat = "0.00%"
$oWorkbook.ActiveSheet.Columns("C").NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...