tags:

views:

121

answers:

1

hi experts

I am using the Excel Automation to create a excel sheet and write data to it.. I want to know how i can make only particular cells to BOLD and how i can make the cell size to autofit to its contents.. Pls help

+4  A: 

There is an easy way to find out, how to do things in Excel using code: macro recording.

Since Excel provides his API through COM-interfaces, VBA, VB scripts and programs written on other languages - are very similiar. So, run macro recording, do the things you want to automate, open recorded macro for edit and look at the code.

In your case it will look like this one:

Range("B2").Select                      -- particular cell selection
ActiveCell.FormulaR1C1 = "123"          -- cell text fill
Selection.Font.Bold = True              -- enabled bold cell style
Columns("B:B").EntireColumn.AutoFit     -- autofitted column

That's VBA code. VB6 will be almost the same, except one thing: you should do this commands with the Excel.Worksheet object. Please refer tutorials like this one: http://www.vbforums.com/showthread.php?t=391665 - to find out more.

Good luck!

Rageous
hey rageous,Thanks a ton.. that worked out... :D
Mahesh N Kini
you are welcome :)
Rageous