Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting excel cell type using interop

Status
Not open for further replies.

WorkerBeeJ

Programmer
Aug 6, 2002
34
US
I'm writing rows out to excel using an interop, and I'm having trouble figuring out how to specify how excel should write certain cells. The many of the numbers have leading zeros, which are being left off because the number type is set to "general" and not "text". Does anyone know how I can set this property so that my leading zeros are left in?

Here's a snippet of my code:

Dim oExcel As New Excel.Application()
oExcel.Visible = False

Dim oWorkbook As Excel.Workbook
oWorkbook = oExcel.Workbooks.Add
Dim oWorksheet As Excel.Worksheet

Dim oRange As Excel.Range
oRange = DirectCast(oWorkSheet.Cells(iRow, 1), Excel.Range)
'(doesn't work: oWorkSheet.Cells(iRow, 1).Type = "Text")
oRange.Value = sBusinessUnit

Thanks!

BTW, using leading ticks would technically work, but my users can't have them in there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top