The method below will add 2 attribute/value pairs to the start tag.
Sub SetAttributes()
Dim strAttributes As String
Dim objElement As IHTMLElement
strAttributes = _
" xmlns= " & """" & _
"http://www.w3.org/1999/xhtml" & _
"""" & " xxx =" & """yyy"""
'choose any element in the document.
Set objElement = _
ActiveDocument.all.tags("html").Item(0)
objElement.outerHTML = "<" & _
Mid(objElement.outerHTML, InStr(1, _
objElement.outerHTML, objElement.tagName), _
Len(objElement.tagName)) & _
strAttributes & _
Mid(objElement.outerHTML, _
InStr(1, objElement.outerHTML, ">"), _
Len(objElement.outerHTML))
End Sub
Sample Tag before procedure was run:
<html>
Sample Tag after procedure was run.
<html xmlns= "http://www.w3.org/1999/xhtml" xxx ="yyy">
The attribute/value pair of xxx="yyy" is not legal but I wanted to demonstrate that the text string is not checked for legality.
The text after the start tag will not be changed.