Welcome to Office Zealot Sign in | Join | Help

IBF: Programatically inserting an IBF Smart Tag

Seems like a lot of folks who work with IBF want to be able to programatically insert an IBF smart tag into a document. So I decided to post some sample code here to show how you can do it. The sample below assumes Microsoft Word 2003, and using VBA, simply prompts you for the name of the smart tag that it will insert in the document. Note that I used the default IBF action handler and the context information string is drawn for the IBF reference sample (or a version very similar). Customize it and use it as you like:

Sub ApplyIBFSmartTag(sText As String)

    Dim rng As Range
    Set rng = Selection.Range
   
    rng.Text = sText
    rng.Select
   
    'Prepare the IBF context XML payload
    Dim sXML As String
    sXML = "<?xml version=""1.0""?><ContextInformation xmlns:xsd=""
http://www.w3.org/2001/XMLSchema"" " + _
                "xmlns:xsi=""
http://www.w3.org/2001/XMLSchema-instance"" " + _
                "MetadataScopeName=""
http://InformationBridge/Sample"" EntityName=""Account"" " + _
                "ViewName=""AccountDefault"" " + _
                "xmlns=""
http://schemas.microsoft.com/InformationBridge/2004/ContextInformation"">" + _
             "<Reference>" + _
                "<AccountName xmlns='urn-SampleSolution-Data' ID='" + rng.Text + "' " + _
                    "iwb:MetadataScopeName='http://InformationBridge/Sample' " + _
                    "xmlns:iwb='http://schemas.microsoft.com/InformationBridge/2004' " + _
                    "iwb:EntityName='Account' iwb:ViewName='AccountDefault' />" + _
             "</Reference>" + _
           "</ContextInformation>"
   
   
    'Create the smart tag and add the data property using the IBF context xml
    Dim st As SmartTag
    Set st = rng.SmartTags.Add("
http://schemas.microsoft.com/InformationBridge/2004#reference", rng)
    st.Properties.Add "data", sXML

End Sub

Sub InsertSmartTag()

    sText = InputBox("What is the account name?", "Insert IBF Account Smart Tag")
    ApplyIBFSmartTag (sText)

End Sub

 

Published Friday, November 19, 2004 1:36 PM by charles

Comments

No Comments

Anonymous comments are disabled