View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
David Biddulph[_2_] David Biddulph[_2_] is offline
external usenet poster
 
Posts: 8,651
Default Set Cell format using VB.NET

In what format did you save the file? If you saved as CSV, remember that CSV
is just comma separated text, so has no formatting data. If you want to
save things like column width, save as xls.
--
David Biddulph

"Hugh" wrote in message
...
Hi JLanthan,

Thank you very much for your help. Your code works fine. I was stuck at
syntex of numeric format. It looks you are the expert. Can I ask one
more
trick? The column width can not be saved and went back to default width
after the file reopen. Any trick? Thank you again.

"JLatham" wrote:

I believe this will do the trick for you - just add these lines of code
to
what you already have displayed here. You'll need to change the sheet
name
and column affected based on what's actually in your workbook, along with
the
proper width value in the first line.

wb.Worksheets("Sheet1").Columns("B:B").ColumnWidth = 15
wb.Worksheets("Sheet1").Columns("B:B").NumberForma t = "m/d/yyyy;@"


"Hugh" wrote:

Hi,

I want to open a exsiting CSV file and set the Data Format of column A
(Date
and time) to Date (m/d/yyyy) and column width to certain number. I can
open
the file but how to set the format? Thanks very much.

My code:

Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Open(FileName)
excel.Visible = True
wb.Activate()