Export (0) Print
Expand All

FrontPage Specific Programmability Items

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
 

Morley Tooke
Microsoft Corporation

April 2001

Applies to:
   Microsoft® FrontPage® 2002

Summary: This article provides late-breaking updates to members of the IFPStyleState object in the Microsoft FrontPage 5.0 Page Object Reference Library that ships with Microsoft FrontPage 2002. (35 printed pages)

The following sections describe late-breaking updates for some of the methods and properties of the IFPStyleState object. The IFPStyleState object belongs to the Microsoft FrontPage 5.0 Page Object Reference Library (FPEDITAX.DLL) that ships with Microsoft FrontPage 2002. These reference documents were not available when FrontPage 2002 was released.

Contents

applyToElement Method applyToRange Method bididir Property borderCollapse Property bottom Property clearAllFormatting Method clearLeft Property clearRight Property clearTextFormatting Method clone Method floatVal Property gather Method gatherFromElement Method getProperty Method IFPStyleState Object ncssBookmark Property ncssCite Property ncssCode Property ncssDfn Property ncssEm Property ncssHyperlink Property ncssKbd Property ncssLabelfor Property ncssLang Property ncssNobr Property ncssSamp Property ncssSpanclass Property ncssSpandir Property ncssStrong Property ncssSub Property ncssSup Property ncssTableCellspacing Property ncssTblAlign Property ncssTextValign Property ncssVar Property propertyCount Property propertyInConflict Method propertySettingReason Method Right Property setProperty Method setToDefault Method

applyToElement Method

Applies style properties to a given element in the current document.

applyToElement(element)

element  Required IHTMLElement object. The name of the element you want to apply a given style property to.

Example

The following example gathers style properties from an element and creates an IFPStyleState object stored in a variable called objSS. Once the object has been created, the styles are applied to the element stored in the variable objLine1.

Sub GatherFromElement()
'Transfers style information from one element to another
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim objLine2 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "<H1>This is line 1</H1>" & vbCrLf _
        & "<H1>This is line 2</H1>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    Set objLine1 = Application.ActiveDocument.all.tags("h1").Item(0)
    Set objLine2 = Application.ActiveDocument.all.tags("h1").Item(1)
        
    Set objSs = Application.ActiveDocument.createStyleState
    objSs.gatherFromElement objLine1
    
    objSs.fontFamily = "arial"
    objSs.color = vbRed
    objSs.backgroundColor = vbBlue
    objSs.backgroundAttachment = "scroll"
    objSs.textAlign = "right"
    objSs.setProperty "background-image", "marble.jpg"
    objSs.backgroundImage = "marble.jpg"
    objSs.textDecorationBlink = True
    objSs.textDecorationLineThrough = True
    objSs.textDecorationOverline = True
    objSs.textDecorationUnderline = True
    objSs.textTransform = "uppercase"
    
    objSs.applyToElement objLine1
            
End Sub

applyToRange Method

Applies a given style state object to a text range.

applyToRange(range)

range  Required IHTMLTxtRange object. The text range for which the style is to be applied.

Example

The following example creates an IFPStyleState object and applies its style properties to a text range stored in the variable objRng.

Sub ApplyStyleToRange()
'Transfers style information from one element to a text range
 
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
 
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<b>Heading 1</b>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    Set objSs = Application.ActiveDocument.createStyleState
    objSs.gather objRng
    
    objSs.fontFamily = "arial"
    objSs.color = vbRed
    objSs.backgroundColor = vbBlue
    objSs.backgroundAttachment = "scroll"
    objSs.textAlign = "right"
    objSs.setProperty "background-image", "marble.jpg"
    objSs.backgroundImage = "marble.jpg"
    objSs.textDecorationBlink = True
    objSs.textDecorationLineThrough = True
    objSs.textDecorationOverline = True
    objSs.textDecorationUnderline = True
    objSs.textTransform = "uppercase"
    
    objSs.applyToRange objRng
            
End Sub

bididir Property

Returns or sets a String that represents the allowed direction of the text in a given text range or element. Read/write.

Remarks

If set to "true", the text range will allow bidirectional text rendering.

Example

The following example set the bididir property of a given text range to True, thus allowing text to appear either left-to-right or right-to-left.

Sub SetDirection()
'Sets the direction of the text for a given range
   
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<i><b>Heading 1</b></i>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    objSs.setProperty "background-color", vbBlue
    objSs.bididir = "true"
    objSs.apply
           
End Sub

borderCollapse Property

Returns or sets a String that determines if borders within a table will appear collapsed.

Example

The following example creates a table and sets the borderCollapse property to True. Any adjacent cells will now appear with collapsed borders.

Sub SetBorders()
'Sets the border collapse property of the table
   
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<table><tr><td>Cell 1</td><td>Cell 2</td></tr></table>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    objSs.borderCollapse = True
    objSs.borderBottomWidth.Value = 10
    objSs.backgroundColor = vbBlue
    objSs.apply
           
End Sub

bottom Property

Returns an IFPStyleLength object that defines the bottom length of the element. Read/write.

Example

The following example creates a new IFPStyleState object and sets the value and units properties of its associated IFPStyleLength object.

Sub SetStyleLength()
'Sets the StyleLength property values
    
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    Dim objSl As IFPStyleLength
     
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<b>Heading 1</b>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    Set objSl = objSs.bottom
    objSl.units = fpLengthUnitsPT
    objSl.value = 4
    objss.bottom = objS1
    objss.apply
    
End Sub

clearAllFormatting Method

Clears any formatting associated with a given text range or element.

Remarks

Use the Apply method to apply the changes to the text range or element.

Example

The following example modifies the properties of a text range, and then uses the clearAllFormatting method to remove any formatting associated with the range.

Sub ClearAllFormatting()
'Clears any formatting from a text range
    
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
 
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<b>Heading 1</b>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    objSs.backgroundColor = vbBlue
    objSs.clearAllFormatting
    objSs.apply
 
End Sub

clearLeft Property

Returns or sets a Boolean that determines which sides of an element's box or boxes may not be adjacent to an earlier floating box. Read/write.

Remarks

Use the clearRight property to clear the right side of a table cell.

Example

The following example creates a table and sets the clearLeft property of the cell in the right column to True. The cell or column to the left of this cell will now appear empty.

Sub ClearLeftSide()
'Clears the left side of a table
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim objLine2 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "<table><tr><td><H1>This is line 1</H1></td>" _
        & "<td>This is line 2</td></tr></table>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    Set objLine1 = Application.ActiveDocument.all.tags("td").Item(0)
    Set objLine2 = Application.ActiveDocument.all.tags("td").Item(1)
        
    Set objSs = Application.ActiveDocument.createStyleState
    objSs.gatherFromElement objLine2
    objSs.clearLeft = True
    objSs.textDecorationUnderline = True
    objSs.apply

End Sub

clearRight Property

Returns or sets a Boolean that determines which sides of an element's box or boxes may not be adjacent to an earlier floating box. Read/write.

Remarks

Use the clearLeft property to clear the right side of a table cell.

Example

The following example creates a table and then sets the clearRight property of the cell on the left hand side of the table. As a result, the right hand side of the table adjacent to the cell will be empty.

Sub ClearRightSide()
'Clears the right side of a table
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim objLine2 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "<table><tr><td><H1>This is line 1</H1></td>" _
        & "<td>This is line 2</td></tr><tr><td><H1>This is line 3</H1></td>" _
        & "<td>This is line 4</td></tr></table>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    Set objLine1 = Application.ActiveDocument.all.tags("td").Item(0)
    Set objLine2 = Application.ActiveDocument.all.tags("td").Item(1)
        
    Set objSs = Application.ActiveDocument.createStyleState
    objSs.gatherFromElement objLine1
    objSs.clearRight = True
    objSs.textDecorationUnderline = True
    objSs.apply

End Sub

clearTextFormatting Method

Clears any formatting associated with an element or text range.

Example

The following example creates a text range and uses the clearTextFormatting method to remove any formatting from the text itself.

Sub ClearTextFormatting()
'Clears any text formatting from a text range
    
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
 
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<b>Heading 1</b>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    objSs.clearTextFormatting
    objSs.apply
 
End Sub

clone Method

Creates a complete copy of a specified IFPStyleState object.

Example

The following example creates an IFPStyleState object called objEl1 and uses the object's clone method to create a copy of the style state object stored in the variable objEl2. Once the IFPStyleState objects are created, they are applied to text ranges in the document.

Sub CloneState()
'Clones a given IFPStyleState object
 
    Dim objDoc As FPHTMLDocument
    Dim objSs1 As IFPStyleState
    Dim objSs2 As IFPStyleState
    Dim objEl1 As IHTMLElement
    Dim objEl2 As IHTMLElement
    
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<H1>Line One</H1><H1>Line Two</H1>"
    
    Set objEl1 = objDoc.all.tags("H1").Item(0)
    Set objEl2 = objDoc.all.tags("H1").Item(1)
    
    Set objSs1 = objDoc.createStyleState
    objSs1.Color = vbRed
    
    Set objSs2 = objSs1.clone
    objSs2.backgroundColor = vbBlue
    
    objSs1.applyToElement objEl1
    objSs2.applyToElement objEl2
    
End Sub

floatVal Property

Returns or sets a String indicating the float setting of the specified element. Valid property values are "none" (default), "left," "right," and "inherit." Read/write.

gather Method

Associates the style properties of a text range with an IFPStyleState object.

gather(range)

range  Required IHTMLTxtRange object. The text range to be associated with the IFPStyleState object.

Example

The following example uses the gather method to associate the style properties of the text range with an IFPStyleState object stored in the variable objSs.

Sub ClearAllFormatting()
'Clears any formatting from a text range
    
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
 
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<b>Heading 1</b>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    objSs.backgroundColor = vbBlue
    objSs.clearAllFormatting
    objSs.apply
 
End Sub

gatherFromElement Method

Gathers style properties from a specified element.

gatherFromElement(element)

element  Required IHTMLElement object. The element associated with a given style.

Example

The following example gathers style properties from an element and creates an IFPStyleState object stored in a variable called objSS. Once the object has been created, the styles are applied to the element stored in the variable objLine1.

Sub GatherFromElement()
'Transfers style information from one element to another
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim objLine2 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "<H1>This is line 1</H1>" & vbCrLf _
            & "<H1>This is line 2</H1>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    Set objLine1 = Application.ActiveDocument.all.tags("h1").Item(0)
    Set objLine2 = Application.ActiveDocument.all.tags("h1").Item(1)
        
    Set objSs = Application.ActiveDocument.createStyleState
    objSs.gatherFromElement objLine1
    
    objSs.fontFamily = "arial"
    objSs.color = vbRed
    objSs.backgroundColor = vbBlue
    objSs.backgroundAttachment = "scroll"
    objSs.textAlign = "right"
    objSs.setProperty "background-image", "marble.jpg"
    objSs.backgroundImage = "marble.jpg"
    objSs.textDecorationBlink = True
    objSs.textDecorationLineThrough = True
    objSs.textDecorationOverline = True
    objSs.textDecorationUnderline = True
    objSs.textTransform = "uppercase"
    
    objSs.applyToElement objLine1
            
End Sub

getProperty Method

Returns a Variant that represents the property value associated with the style property.

getProperty(strAttributeName)

strAttributeName  Required String. The name of the property whose value is to be returned.

Example

The following example returns the value associated with a given style property.

Sub GetSSProperties()
'Returns the value associated with style state properties.
 
    Dim objSs As IFPStyleState
    Dim objdoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    
    Set objdoc = Application.ActiveDocument
    objdoc.body.innerHTML = "Hello World"
    
    Set objRng = objdoc.body.createTextRange
    Set objSs = objdoc.createStyleState
    
    objSs.gather objRng
    objSs.Color = vbRed  '  vbRed = 255
    objSs.backgroundColor = vbBlue  '  vbBlue = 16711680
    objSs.Apply
    
    Set objRng = Nothing
    Set objSs = Nothing
    
    Set objRng = objdoc.body.createTextRange
    Set objSs = objdoc.createStyleState
    objSs.gather objRng
    MsgBox "Body background color value is " & objSs.getProperty("background-color")
    MsgBox "Body color value is " & objSs.getProperty("color")
    
End Sub

IFPStyleState Object

Contains information about the styles associated with a given element or text range on the current page. The IFPStyleState object allows you to view and edit any style property associated with a given element. Once style properties are modified, Microsoft FrontPage uses the new style information to render the new text based on the original styles.

Using the IFPStyleState object

Use the CreateStyleState property of the FPHTMLDocument object to create an IFPStyleState object. The following example creates a new IFPStyleState object and stores it in a variable called objSs.

Sub NewStyleState()
'Creates a new style state object

    Dim objSs As IFPStyleState            
    Set objSs = Application.ActiveDocument.createStyleState
        
End Sub

Use the gather method to associate a style state with a specified element or range. The following example creates an IFPStyleState object, associates it with a text range on the active document, and modifies its properties. The resulting text will now be rendered with the new styles.

Sub ChangeStyleState()
'Changes the style state of a given text range

    Dim objSs As IFPStyleState
    Dim objRng As IHTMLTxtRange
    
    Application.ActiveDocument.body.innerHTML = "Hello Style State World"
    Set objRng = Application.ActiveDocument.body.createTextRange
    Set objSs = Application.ActiveDocument.createStyleState
    
    objSs.gather objRng
    objSs.fontWeight = 700
    objSs.fontFamily = "arial"
    objSs.Apply
    
End Sub

Use the apply method to apply any changes made to the text range or element.

ncssBookmark Property

Returns or sets a String that specifies an HTML bookmark for a given element. Bookmarks are used to provide a navigation or reference point within an HTML document. Read/write.

Example

The following example creates a new IFPStyleState object and sets a bookmark for the new element.

Sub SetBookMark()
'Sets the Bookmark value for an element
    
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    Dim objSl As IFPStyleLength
 
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<b>Introduction</b>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    objSs.ncssBookmark = "#Intro"
    objSs.apply

End Sub

ncssCite Property

Returns or sets a Boolean that specifies that the range will be enclosed within a CITE element. Cited text normally appears in italics. Read/write.

Example

The following example creates a range of text and uses the ncssCite property to cite the text. The text will now be rendered as bold and italic.

Sub SetCitedText()
'Sets text as cited
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "This is sample text. <b>This is bold and will be cited.</b>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    Set objLine1 = Application.ActiveDocument.all.tags("B").Item(0)
            
    Set objSs = Application.ActiveDocument.createStyleState
    objSs.gatherFromElement objLine1
    
    objSs.ncssCite = True
    objSs.apply
            
End Sub

ncssCode Property

Returns or sets a Boolean that determines if a text range will appear as code. The CODE element is used to denote code in an HTML document. Read/write.

Example

The following example encloses the first instance of bold text within a CODE element. The text will now appear as code.

Sub SetCodeWrap()
'Wraps a text range in Code tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "This is sample text. <br> <b>This is bold and will appear as code.</b>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    Set objLine1 = Application.ActiveDocument.all.tags("B").Item(0)
            
    Set objSs = Application.ActiveDocument.createStyleState
    objSs.gatherFromElement objLine1
    
    objSs.ncssCode = True
    objSs.apply
            
End Sub

ncssDfn Property

Returns or sets a Boolean that indicates if the text range will be enclosed in a DFN element, indicating the defining instance of a text range. Read/write.

Example

The following example uses the ncssDFN property to enclose the first instance of italic text in the document within a DFN element.

Sub SetNcssDfn()
'Wraps a text range in DFN tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "This is sample text. <br>
              <I>This is italicized and will appear within DFN tags.</I>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    Set objLine1 = Application.ActiveDocument.all.tags("I").Item(0)
            
    Set objSs = Application.ActiveDocument.createStyleState
    objSs.gatherFromElement objLine1
    
    objSs.ncssDfn = True
    objSs.apply
            
End Sub

ncssEm Property

Returns or sets a Boolean that specifies that a text range will be enclosed within EM elements, indicating the emphasis style. Read/write.

Example

The following example marks all text within the first B element in the active document with the emphasis style.

Sub SetNcssEm()
'Wraps a text range in Em tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "This is sample text. <br> 
              <b>This is italicized and will appear within Em tags.</b>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    Set objLine1 = Application.ActiveDocument.all.tags("b").Item(0)
            
    Set objSs = Application.ActiveDocument.createStyleState
    objSs.gatherFromElement objLine1
    
    objSs.ncssEm = True
    objSs.apply
            
End Sub

ncssHyperlink Property

Returns or sets a String that specifies the URL of the hyperlink. Setting the ncssHyperLink property of a text range turns it into a hyperlink. Read/write.

Example

The following example creates hyperlinks from all text ranges enclosed within CITE elements. The user is prompted for the URL for each citation in the active document.

Sub SetHyperlInk()
'Wraps a text range in hyperlink tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
    Dim strURL As String
    
    strHTML = "This is sample text. <br> 
              <cite>This is italicized and will appear as a hyperlink.</cite>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    For Each objLine1 In Application.ActiveDocument.all.tags("cite")
        Set objSs = Application.ActiveDocument.createStyleState
        objSs.gatherFromElement objLine1
        strURL = InputBox("Enter a URL for the hyperlink:" & _
            vbCr & objLine1.innerText)
        objSs.ncssHyperlink = Trim(strURL)
        objSs.apply
    Next objLine1

End Sub

ncssKbd Property

Returns or sets a Boolean that determines if the text in a given text range will be rendered with a fixed-width font. Read/write.

Example

The following example sets all text ranges within CITE elements to be rendered with a fixed-width font.

Sub SetWidth()
'Wraps a text range in kbd tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "This is sample text. <br> 
              <cite>This is cited and will appear with a fixed-width font.</cite>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    For Each objLine1 In Application.ActiveDocument.all.tags("cite")
        Set objSs = Application.ActiveDocument.createStyleState
        objSs.gatherFromElement objLine1
        objSs.ncssKbd = True
        objSs.apply
    Next objLine1

End Sub

ncssLabelfor Property

Returns or sets a String that specifies a label for a given text range. Read/write.

Example

The following example associates the label "Citation" with all text ranges in the active document within CITE elements.

Sub SetLabel()
'Associates a label with a text range
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "This is sample text. <br> 
              <cite>This is cited and will within the labeled text.</cite>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    For Each objLine1 In Application.ActiveDocument.all.tags("cite")
        Set objSs = Application.ActiveDocument.createStyleState
        objSs.gatherFromElement objLine1
        objSs.ncssLabelfor = "Citation"
        objSs.apply
    Next objLine1

End Sub

ncssLang Property

Returns or sets an Integer that specifies the language format of the current page. Read/write.

ncssNobr Property

Returns a Boolean that specifies that an associated range will be rendered without line breaks. Read/write.

Example

The following example encloses all text ranges currently within H1 elements within NOBR elements. All ranges with the heading 1 style will no longer wrap.

Sub NoBRHeading()
'Wraps all H1 tagged ranges in Nobr tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "<h1>This is a sample heading that will not be wrapped</h1>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    For Each objLine1 In Application.ActiveDocument.all.tags("h1")
        Set objSs = Application.ActiveDocument.createStyleState
        objSs.gatherFromElement objLine1
        objSs.ncssNobr = True
        objSs.apply
    Next objLine1

End Sub

ncssSamp Property

Returns or sets a Boolean that indicates whether given text range is enclosed within a SAMP element. Read/write.

Example

The following example encloses all text ranges currently within CODE elements within SAMP elements. The ranges will now appear with the formatting associated with samples.

Sub NcssSampleTag()
'Wraps all code tagged ranges in Samp tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "<code>This is a sample that will appear with the associated sample style.</code>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    For Each objLine1 In Application.ActiveDocument.all.tags("code")
        Set objSs = Application.ActiveDocument.createStyleState
        objSs.gatherFromElement objLine1
        objSs.ncssSamp = True
        objSs.apply
    Next objLine1

End Sub

ncssSpanclass Property

Returns or sets a String that represents the class of the specified SPAN element. Read/write.

ncssSpandir Property

Returns or sets a String that specifies the direction of the text within the specified SPAN element. Read/write.

ncssStrong Property

Returns a Boolean that encloses a given text range within a STRONG element. Read/write.

Example

The following example encloses all B elements in the current document within STRONG elements.

Sub NcssStrongTag()
'Wraps all bold tagged ranges in Strong tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
        
    strHTML = "<b>This is a sample that will be wrapped in a STRONG element.</b>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    For Each objLine1 In Application.ActiveDocument.all.tags("b")
        Set objSs = Application.ActiveDocument.createStyleState
        objSs.gatherFromElement objLine1
        objSs.ncssStrong = True
        objSs.apply
    Next objLine1

End Sub

ncssSub Property

Returns a Boolean that specifies if the text will appear as subscript. Read/write.

Example

The following example formats all text within STRONG elements as subscript.

Sub NcssSubTag()
'Wraps all code tagged ranges in Sub tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
    
    strHTML = "<strong>This is a sample that will appear as subscript.</strong>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    For Each objLine1 In Application.ActiveDocument.all.tags("strong")
        Set objSs = Application.ActiveDocument.createStyleState
        objSs.gatherFromElement objLine1
        objSs.ncssSub = True
        objSs.apply
    Next objLine1

End Sub

ncssSup Property

Returns or sets a Boolean that specifies whether text will appear as superscript. Read/write.

Example

The following example sets all text enclosed in STRONG elements to appear as superscript.

Sub NcssSupTag()
'Wraps all code tagged ranges in Sup tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
        
    strHTML = "<strong>This is a sample that will appear as superscript.</strong>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    For Each objLine1 In Application.ActiveDocument.all.tags("strong")
        Set objSs = Application.ActiveDocument.createStyleState
        objSs.gatherFromElement objLine1
        objSs.ncssSup = True
        objSs.apply
    Next objLine1

End Sub

ncssTableCellspacing Property

Returns or sets an Integer that specifies the cell spacing of a given table. Read/write.

ncssTblAlign Property

Returns or sets a String that represents the alignment of a given table. Read/write.

Example

The following example sets the alignment of a given table to right. The table will now appear aligned to the right-hand side of the page.

Sub SetTableAlign()
'Sets the alignment of a given table
   
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<table><tr><td>Cell 1</td><td>Cell 2</td></tr></table>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    objSs.borderCollapse = True
    objSs.ncssTblAlign = "right"
    objSs.apply
               
End Sub

ncssTextValign Property

Returns or sets a String that represents the vertical alignment of the text in a given table. Read/write.

Example

The following example sets the vertical alignment of the text in the given table to bottom. The text will now appear at the bottom of each table cell.

Sub SetTableAlign()
'Sets the text alignment of a given table
   
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<table height=107><tr><td>Cell 1</td><td>Cell 2</td></tr></table>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    objSs.borderCollapse = True
    objSs.ncssTextValign = "bottom"
    objSs.apply
               
End Sub

ncssVar Property

Returns or sets a Boolean that determines if the text will be enclosed in a VAR element. The VAR element is used to specify a programming variable and is typically rendered as italic. Read/write.

Example

The following example encloses all text currently within STRONG elements within VAR tags. The text will now appear bold and italic.

Sub NcssVarTag()
'Wraps all strong tagged ranges in Var tags
 
    Dim objSs As IFPStyleState
    Dim objLine1 As IHTMLElement
    Dim strHTML As String
        
    strHTML = "<strong>This is a sample that will appear within a VAR element.</strong>"
    
    Application.ActiveDocument.body.innerHTML = strHTML
    
    For Each objLine1 In Application.ActiveDocument.all.tags("strong")
        Set objSs = Application.ActiveDocument.createStyleState
        objSs.gatherFromElement objLine1
        objSs.ncssVar = True
        objSs.apply
    Next objLine1

End Sub

propertyCount Property

Returns an Integer that represents the number of style properties associated with the current element or text range.

Example

The following example displays the number of properties associated with a given text range.

Sub DisplayPropertyNumber()
'Displays the number of properties available in the current range
   
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<i><b>Heading 1</b></i>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    objSs.setProperty "background-color", vbBlue
    MsgBox "The total number of properties available is:  " & objSs.propertyCount
    objSs.apply
           
End Sub

propertyInConflict Method

Returns a Boolean that indicates if a style property is in conflict.

propertyInConflict(strPropertyName)

strPropertyName  Required String. The name of the property.

Example

The following example sets the background property of the text range and then returns a message based on the result of the method.

Sub DisplayConflict()
'Displays True if background property is in conflict
   
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
 
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<b>Heading 1</b>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    objSs.setProperty "background-color", vbBlue
    objSs.apply
    If objSs.propertyInConflict("background-color") = True Then
        MsgBox "The property is in conflict."
    Else
        MsgBox "The property is not in conflict."
    End If
     
End Sub

propertySettingReason Method

Returns an Integer that specifies the numeric value of the reason.

propertySettingReason(strPropertyName)

strPropertyName  Required. A String that represents the property setting reason.

Remarks

The property setting reasons and their numeric values are as follows:

ReasonValue
ssrNoReason 0
ssrInConflict1
ssrUninheritedDefault 2
ssrCloneProps 3
ssrStoredStyles 4
ssrInheritFromBody5
ssrBgPropOfSpanningParent6
ssrBgPropOfTableRowSection7
ssrLegendTextAlign8
ssrBodyColorInTable9
ssrHeaderNestedInSupOrSub10
ssrHTMLSemanticStructuralTagDefault11
ssrHTMLSemanticSpanningTagDefault12
ssrHTMLSpanningFormattingTag13
ssrHTMLFontTag14
ssrHTMLBaseFontTag15
ssrCSSStyleSheetRule16
ssrCSSStyleSheetRuleBangImportant17
ssrCSSStyleAttribute18
ssrCSSStyleAttributeBangImportant19
ssrHTMLAttr20
ssrHTMLBorderAttr 21
ssrHTMLAlignAttr 22
ssrHTMLHSpaceAttr23
ssrHTMLVSpaceAttr24
ssrBODYAttr 25
ssrDTC26
ssrInternalVisibilityControl27
ssrTheme28
ssrFunkyBotBusiness 29
ssrListImageIndent30
ssrCellHTMLPropInheritance 31
ssrCellFloating 32
ssrCellPaddingFromTable33
ssrCellBorderFromTable34
ssrFloatImpliesAlign 35
ssrDoubleBorderMustBe3High36
ssrPositionedCantFloat 37
ssrStaticObjectsNoZOrder 38
ssrListItemHeight39
ssrEscherChild 40
ssrVerticalAlignSetsTextVAlign 41
ssrHRMarginIsPadding 42
ssrIME43
ssrSetLangForINPUTTag 44
ssrFloatMarginIsNonZero 45
ssrBodyMarginNotLessThanZero 46
ssrSupOrSubFormattingTag 47
ssrHTMLCentering 48
ssrTextAlignSetsStructAlign49
ssrPositionResetsBGProps 50
ssrComputedMargin 51

Right Property

Returns an IFPStyleLength object that represents the right side of an element.

Example

The following example creates a new IFPStyleState object and sets the value and units properties of its associated right IFPStyleLength object.

Sub SetStyleLength()
'Sets the StyleLength property values
    
    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    Dim objSl As IFPStyleLength
 
    Set objDoc = Application.ActiveDocument
    
    objDoc.body.innerHTML = "<b>Heading 1</b>"
    Set objSs = objDoc.createStyleState
    Set objRng = objDoc.body.createTextRange
    
    objSs.gather objRng
    Set objSl = objSs.Right
    objSl.units = fpLengthUnitsPT
    objSl.value = 4
    objSs.Right = objS1
    objSS.apply 
    
End Sub

setProperty Method

Sets an IFPStyleState object's style property with a specified value.

setProperty(strAttributeName, AttributeValue)

strAttributeName  Required String. The name of the property to be modified.

AttributeValue  Required Variant. The new value for the property.

Remarks

Use the apply method in order to apply the changes to the text range or element.

Example

The following example uses the setProperty method to set the background color of the IFPStyleState object to vbBlue.

Sub SetBackground()
'Sets style properties with setproperty method

    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    
    Set objDoc = Application.ActiveDocument
    objDoc.body.innerHTML = "Hello World"
    
    Set objRng = objDoc.body.createTextRange
    Set objSs = objDoc.createStyleState
    objSs.gather objRng
    objSs.setProperty "background-color", vbBlue
    objSs.apply
    MsgBox "Body background color is " & objSs.getProperty("background-color")
        
End Sub

setToDefault Method

Sets a specified property to its default value.

setToDefault(strAttributeName)

strAttributeName  Required String. The name of the property.

Remarks

Use the apply method to apply the changes to the text range or element.

Example

The following example sets the background color of a text range to its default value.

Sub SetToDefault()
'Sets style property to its default value

    Dim objSs As IFPStyleState
    Dim objDoc As FPHTMLDocument
    Dim objRng As IHTMLTxtRange
    
    Set objDoc = Application.ActiveDocument
    objDoc.body.innerHTML = "Hello World"
    
    Set objRng = objDoc.body.createTextRange
    Set objSs = objDoc.createStyleState
    objSs.gather objRng
    objSs.setToDefault "background-color"
    objSs.apply
    MsgBox "Default body background color is " & objSs.getProperty("background-color")
        
End Sub

Show:
© 2014 Microsoft