Formatting in Excel from VB6

I am using Excel Automation to create an excel sheet and write data to it. I want to know how I can only make certain cells for BOLD and how can I make the cell size auto-fit for my content. Pls help

+1


a source to share


1 answer


There is an easy way to learn how to do something in Excel using code: macro photography.

Because Excel exposes its API through COM interfaces, VBA, VB scripts, and programs written in other languages ​​are very similar. So, start a macro, do what you want to automate, open the recorded macro for editing and look at the code.

In your case it will look like this:



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

      

This VBA code. VB6 will be much the same except for one thing: you have to do it with the Excel.Worksheet object. Please refer to the following tutorials: http://www.vbforums.com/showthread.php?t=391665 - to find out more.

Good luck!

+5


a source







All Articles