Can I code Styles

  • Thread starter Thread starter Wired Hosting News
  • Start date Start date
W

Wired Hosting News

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?
 
Why don't you record a macro as you create a style manually to see how it is
done?

--
Jim
| 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?
|
|
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top