How can a format a cell in Excel to currency from VB?
I think I have the first bit but I can not figure it out
Also how do I format column B so that everything in it is centred?
x1sheet.Cells(10, 2).
Thanks
Printable View
How can a format a cell in Excel to currency from VB?
I think I have the first bit but I can not figure it out
Also how do I format column B so that everything in it is centred?
x1sheet.Cells(10, 2).
Thanks
Once you have the file open in VB, create a Range and then do your formating. Also, best way to find out how to do anything in Excel or Word is to record a macro.
VB Code:
Dim objExcel As Excel.Application Dim objWorkSheet As Excel.Worksheet Dim r As Excel.Range ' section opening Excel not included. ' open the file objExcel.Workbooks.Open "C:\my documents\newfile.xls" ' create reference to sheet3 Set objWorkSheet = objExcel.Worksheets.Item("sheet3") ' activate sheet3 objWorkSheet.Activate ' make it visible objExcel.Visible = True ' create range object Set r = objWorkSheet.Range("B1:B35") ' set text alignment and Currency r.NumberFormat = "$#,##0.00" r.HorizontalAlignment = xlRight r.VerticalAlignment = xlBottom