Style definitions in VBA

B

Bob Phillips

Simple enough

Selection.Style = "Bob"

and

Selection.BorderAround ColorIndex:=3, Weight:=xlThick

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
B

Bob Phillips

With ActiveWorkbook.Styles
Set oStyle = .Add(Name:="Bookman Top Border")
oStyle.Borders(xlTop).LineStyle = xlContinuous
oStyle.Font.Bold = True
oStyle.Font.Name = "Bookman"
End With
Worksheets(1).Range("A25:A30").Style = oStyle.Name


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
S

serdar

I want to create a style (cell format) and use it whenever i need in the
code. Otherwise bordering a cell for instance needs a lot of lines to code
as "macro recorder" suggested to me. By the way what is the easiest way to
border for sides of a cell? Is it possible to do it with a single line?

-Does the dataype Style helps? I am going to check the internet but your
help could make me faster.

thanks.
 
S

serdar

I am not "selecting" any range in my code. I should better create a new
style object and assign it to the cell when i need it.

Thanks.
 
S

serdar

Just to know:

this creates a new style,

With ActiveWorkbook.Styles.Add(Name:="Bookman Top Border")
.Borders(xlTop).LineStyle = xlDouble
.Font.Bold = True
.Font.Name = "Bookman"
End With
Worksheets(1).Range("A25:A30").Style = "Bookman Top Border"

how to initialize a style object like:

Dim myStyle As Style


thanks.
 
Top