ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can I code Styles (https://www.excelbanter.com/excel-programming/354502-can-i-code-styles.html)

Wired Hosting News

Can I code Styles
 
If I run into a situaton where I have an addin formatting cells to a
particular style:

ws.Column("D:D").style = "Currency"

and the workbook that is active at the time does not have that style, is it
possible to code the workbook or add the style to the workbook, prior to
running the rest of the macro?



Jim Rech

Can I code Styles
 
Why don't you record a macro as you create a style manually to see how it is
done?

--
Jim
"Wired Hosting News" wrote in message
...
| If I run into a situaton where I have an addin formatting cells to a
| particular style:
|
| ws.Column("D:D").style = "Currency"
|
| and the workbook that is active at the time does not have that style, is
it
| possible to code the workbook or add the style to the workbook, prior to
| running the rest of the macro?
|
|



Dave Peterson

Can I code Styles
 
You can test for it first and then rebuild it using those recorded statements:

Option Explicit
Sub testme()

Dim myStyle As Style

Set myStyle = Nothing
On Error Resume Next
Set myStyle = ActiveWorkbook.Styles("Currency")
On Error GoTo 0

If myStyle Is Nothing Then
'use your recorded code here to add the style
Else
'it's already there, do nothing special
End If

End Sub




Wired Hosting News wrote:

If I run into a situaton where I have an addin formatting cells to a
particular style:

ws.Column("D:D").style = "Currency"

and the workbook that is active at the time does not have that style, is it
possible to code the workbook or add the style to the workbook, prior to
running the rest of the macro?


--

Dave Peterson


All times are GMT +1. The time now is 07:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com