Results 1 to 1 of 1
2001-03-06, 03:58 #1
- Join Date
- Feb 2001
- Yilgarn region of Toronto, Ontario
- Thanked 0 Times in 0 Posts
Code: test for existence of a style
I have re-written my test for existence of a style. Mainly because I found an EXIT FOR in some other code, and I wanted to be rid of it.
This function is used at least in my apply-style fucntions, which are given a style name (paragraph or character) and apply that style; if the style does not exist, the functions must create it on-the-fly. This because I have table-driven applications where the user can nominate any style they want to highlight the results of the job.
Immediately below is some feedback I received on the old board. If anyone can recognise the authour, I'd like to re-establish contact.
'If I am reading your code correctly, it checks styles that already exist in a document
' to see which ones are built-in styles.
' My problem is that I am trying to verify if a proposed new style name
' is reserved exclusively for a Word built-in style that has not yet been used
' in the active document.
' Unfortunately, because the style cannot be created
' unless the style name is valid, I can't check the style's built-in property.
' However, I can't create the style if the name is invalid
' because it reserved for use by a Word built-in style.
' Is there a way around this conundrum?
<pre>Function boolStyleExists(strStylename As String) As Boolean
' Procedure : boolStyleExists
' Description: Determine if a style is/has been defined in the document.
' Copyright: Chris Greaves Inc.
' Inputs: String (style name)
' Returns: FALSE if we need to define the style before using it.
' Assumes: None.
' Side Effects: None.
' Tested: By the calls shown below.
boolStyleExists = False
On Error Resume Next
boolStyleExists = ActiveDocument.Styles(strStylename).InUse
'MsgBox boolStyleExists("Normal") ' TRUE; a paragraph style
'MsgBox boolStyleExists("Default Paragraph Font") ' TRUE; a character style
'MsgBox boolStyleExists("This can't possibly exist, can it?") ' False