WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Change Currency Formats in Excel


;Winbatch 2005C - Changing Currency Formats in Excel
;                 using NumberFormat may fail
;                 use NumberFormatLocal instead - Excel 2000 or greater
;
;Stan Littlefield, June 8, 2005
;/////////////////////////////////////////////////////////
oXL=0
oXL = CreateObject("Excel.Application")
If oXL == 0 Then Exit
oXL.Visible          = 1  
oXL.ScreenUpdating   = 1   
oXL.UserControl      = 1
oXL.DisplayAlerts    = 0
nOld = oXL.SheetsInNewWorkbook 
oXL.SheetsInNewWorkbook = 1 
oXL.WorkBooks.Add()
oXL.SheetsInNewWorkbook = nOld

cUSA = "$#,##0.00;[Red]$#,##0.00"
cUK = "£* #,##0.00_);[Red]£* (#,##0.00)" 
cEuro = "\€* #,##0.00_);[Red]\€* (#,##0.00)" 

oWS = oXL.Activeworkbook.Worksheets(1)
oWS.Activate()

oWS.Cells(1,1).Value = "USA"
oWS.Cells(1,2).Value = 80000
oWS.Cells(1,2).NumberFormatLocal = cUSA
oWS.Cells(1,3).Value = -80000
oWS.Cells(1,3).NumberFormatLocal = cUSA


oWS.Cells(3,1).Value = "UK"
oWS.Cells(3,2).Value = 80000
oWS.Cells(3,2).NumberFormatLocal = cUK
oWS.Cells(3,3).Value = -80000
oWS.Cells(3,3).NumberFormatLocal = cUK

oWS.Cells(5,1).Value = "EURO"
oWS.Cells(5,2).Value = 80000
oWS.Cells(5,2).NumberFormatLocal = cEuro
oWS.Cells(5,3).Value = -80000
oWS.Cells(5,3).NumberFormatLocal = cEuro


oWS.UsedRange.Columns.Autofit()

oWS=0
oXL=0

Exit

Article ID:   W17145
File Created: 2007:07:03:14:28:28
Last Updated: 2007:07:03:14:28:28