Share via


execCommand Method

Executes a specified action on the current document, current selection, or the specified range, and then returns a Boolean that indicates whether the command completed successfully.

expression.execCommand(cmdID, showUI, value)

*expression   * Required. An expression that returns one of the objects in the Applies To list.

command

The cmdID parameter can be one of the following String values:

Command Description
BackColor Sets the background color of the current selection. The value parameter must specify the color name of the background color. For available color names, see the HTML Color Table.

The following code sets the background color for the selection to yellow.

ActiveDocument.execCommand "backcolor", False, "yellow"

Note  You must use a color name and not a Web-safe RGB color value, such as #663399.

Copy Copies the current selection to the Clipboard.

The following code copies the selection to the Clipboard.

ActiveDocument.execCommand "copy"
CreateBookmark Creates a bookmark anchor around the selected text.

The following code creates a bookmark anchor named "newbookmark" around the selected text.

ActiveDocument.execCommand "createbookmark", False, "newbookmark"
CreateLink Inserts a hyperlink on the current selection or displays a dialog box enabling the user to specify a URL to insert as a hyperlink on the current selection. The value parameter must specify the URL of the hyperlink.

The following code creates a hyperlink to the Microsoft Web site.

ActiveDocument.execCommand "createlink", False, _
    "http://www.microsoft.com"
Cut Cuts the current selection and copies it to the Clipboard.

The following code cuts the selected text and places a copy in the Clipboard.

ActiveDocument.execCommand "cut"
Delete Deletes the current selection without storing a copy of it.

The following code deletes the selected text.

ActiveDocument.execCommand "delete"
FontName Sets the font for the current selection. The value parameter must specify the name of the font to use.

The following code specifies the Stencil font for the selected text.

ActiveDocument.execCommand "fontname", False, "stencil"

Note  If the font name specified in the value parameter is not available on the users machine, the selected text will display in the browser in the default font.

FontSize Sets the font size for the current selection. The value parameter must specify the size of the font to use. For possible values for font size, see the fontSize property.

The following code specifies a font size for the selected text of 115 percent of the size of the font setting for the parent element.

ActiveDocument.execCommand "fontsize", False, "115%"
ForeColor Sets the color of the selected text. The value parameter must specify the color name of the text color. For available color names, see the HTML Color Table.

The following code sets the color of the selected text to red.

ActiveDocument.execCommand "forecolor", False, "red"

Note  You must use a color name and not a Web-safe RGB color value, such as #663399.

Indent Indents the selected text by inserting a BLOCKQUOTE element around the selected text and any surrounding text that belongs to the same parent element.

The following code indents the selected text and related surrounding text.

ActiveDocument.execCommand "indent"
InsertButton Inserts a BUTTON element at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a BUTTON element with an id attribute value of "newbutton" at the insertion point.

ActiveDocument.execCommand "insertbutton", False, "newbutton"
InsertFieldset Inserts a FIELDSET element at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a FIELDSET element with an id attribute value of "newfield" at the insertion point.

ActiveDocument.execCommand "insertfieldset", False, "newfield"
InsertHorizontalRule Inserts an HR element at the insertion point. If text is selected, the new element overwrites the selected text.

The following code inserts an HR element at the insertion point.

ActiveDocument.execCommand "inserthorizontalrule"
InsertIFrame Inserts an IFRAME element at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify the source file displayed in the inline frame.

The following code inserts an IFRAME element at the insertion point with a src attribute of "form.htm".

ActiveDocument.execCommand "insertiframe", False, "form.htm"
InsertImage Inserts an IMG element at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify the image file name.

The following code inserts the chelan.jpg image file into the document at the insertion point.

ActiveDocument.execCommand "insertimage", False, "chelan.jpg"
InsertInputButton Inserts an INPUT element of type "button" at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a new input button with an id attribute value of "newbutton" at the insertion point.

ActiveDocument.execCommand "insertinputbutton", False, "newbutton"
InsertInputCheckbox Inserts an INPUT element of type "checkbox" at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a new check box with an id attribute value of "newcheckbox" at the insertion point.

ActiveDocument.execCommand "insertinputcheckbox", False, "newcheckbox"
InsertInputFileUpload Inserts an INPUT element of type "fileupload" at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.Overwrites a file upload control on the text selection.

The following code inserts an INPUT element of type "fileupload" at the insertion point.

ActiveDocument.execCommand "insertinputfileupload", False, "newfile"
InsertInputHidden Inserts an INPUT element of type "hidden" at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a hidden INPUT element at the insertion point.

ActiveDocument.execCommand "insertinputhidden", False, "newhidden"
InsertInputPassword Inserts an INPUT element of type "password" at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a text box for entering passwords at the insertion point.

ActiveDocument.execCommand "insertinputpassword", False, "newpassword"
InsertInputReset Inserts an INPUT element of type "reset" at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a Reset button at the insertion point.

ActiveDocument.execCommand "insertinputreset", False, "newresetbutton"
InsertInputSubmit Inserts an INPUT element of type "submit" at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a Submit button at the insertion point.

ActiveDocument.execCommand "insertinputsubmit", False, "newsubmitbutton"
InsertInputText Inserts an INPUT element at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a one-line text box at the insertion point.

ActiveDocument.execCommand "insertinputtext", False, "newtextbox"
InsertMarquee Inserts a MARQUEE element at the insertion point. If text is selected, the new element overwrites the selected text.

The following code inserts a new MARQUEE element at the insertion point.

ActiveDocument.execCommand "insertmarquee"
InsertOrderedList If text is selected, toggles the text selection between items in an ordered list and normal paragraphs. If no text is selected, inserts an OL element with one LI element.

The following inserts an ordered list at the insertion point or converts the selected text to an ordered list.

ActiveDocument.execCommand "insertorderedlist"
InsertParagraph Inserts a P element at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following inserts a new paragraph at the insertion point.

ActiveDocument.execCommand "insertparagraph", True, "newpara"
InsertSelectDropdown Inserts a SELECT element at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following inserts a new drop-down list at the insertion point.

ActiveDocument.execCommand "insertselectdropdown", True, "newdropdownlist"
InsertSelectListbox Inserts a SELECT element that contains the multiple attribute at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a list box at the insertion point.

ActiveDocument.execCommand "insertselectlistbox", True, "newlistbox"
InsertTextArea Inserts a TEXTAREA element at the insertion point. If text is selected, the new element overwrites the selected text. Use the value parameter to specify an id attribute for the new element.

The following code inserts a multiple-line text box at the insertion point.

ActiveDocument.execCommand "inserttextarea", True, "newtextarea"
InsertUnorderedList If text is selected, toggles the text selection between items in a bulleted list and normal paragraphs. If no text is selected, inserts a UL element with one LI element.

The following inserts a bulleted list at the insertion point or converts the selected text to a bulleted list.

ActiveDocument.execCommand "insertunorderedlist"
Italic Toggles the current selection between italic and nonitalic.

The following toggles italics for the selected text.

ActiveDocument.execCommand "italic"
JustifyCenter Centers the selected text and any surrounding text that belongs to the same parent element. If the affected text alignment is already centered, then this command returns the text to the default alignment.

The following code centers the selected text and any related text.

ActiveDocument.execCommand "justifycenter"
JustifyLeft Left aligns the selected text and any surrounding text that belongs to the same parent element. If the affected text alignment is already left aligned, then this command returns the text alignment to the default alignment.

The following code left aligns the selected text and any related text.

ActiveDocument.execCommand "justifyleft"
JustifyRight Right aligns the selected text and any surrounding text that belongs to the same parent element. If the affected text alignment is already right aligned, then this command returns the text alignment to the default alignment.

The following code right aligns the selected text and any related text.

ActiveDocument.execCommand "justifyright"
Outdent Decreases by one increment the indentation of the selected text by removing a BLOCKQUOTE element from around the selected text and any surrounding text that belongs to the same parent element. If there are no surrounding BLOCKQUOTE elements, this command does nothing.

Decreases by one the indentation of the selected text and any related text.

ActiveDocument.execCommand "outdent"
Paste Overwrites the contents of the Clipboard on the current selection.

The following code pastes the contents of the Clipboard into the document at the cursor position or overwrites any selected text.

ActiveDocument.execCommand "paste"
RemoveFormat Removes the font and character formatting from the current selection.

The following code removes all formatting from the selected text.

ActiveDocument.execCommand "removeformat"
SelectAll Selects the entire document.

The following code selects all contents in the active document.

ActiveDocument.execCommand "selectall"
UnBookmark Removes any bookmark from the current selection. If the selected text is not all the text affected by a bookmark anchor, the bookmark anchor will close before and reopen after the selected text. It the selected text is all the text affected by a bookmark anchor, the entire bookmark is removed from the document. If multiple bookmarks are included in the selection, then all bookmarks are removed from the selection.

The following code removes all bookmarks from the selected text.

ActiveDocument.execCommand "unbookmark"
Underline Toggles the current selection between underlined and not underlined.

The following code toggles underlining for the selected text.

ActiveDocument.execCommand "underline"
Unlink Removes any hyperlinks from the current selection. If the selected text is not all the text affected by a hyperlink, the hyperlink will close before and reopen after the selected text. It the selected text is all the text affected by a hyperlink, the entire hyperlink is removed from the document. If multiple hyperlinks are included in the selection, then all hyperlinks are removed from the selection.

The following removes all hyperlinks from the selected text.

ActiveDocument.execCommand "unlink"
Unselect Clears the current selection.

The following code unselects the text in the active document and places the cursor at the beginning of the document.

ActiveDocument.execCommand "unselect"

showUI    Optional. True displays the dialog box associated with the command, if there is a corresponding dialog box. The default value is False.

value    Optional. A Variant that specifies any additional arguments associated with the cmdID parameter. For example, if the cmdID parameter is specifies the BackColor command, then the value parameter contains the color name for the background color of the selection.

Remarks

If the command specified in the CmdID parameter sets a value, then the value parameter is required to complete the command.

If the value parameter contains a string that represents the value of the id attribute for an element and there already exists an element with the same id attribute value, the execCommand method will increment the id attribute string. For example, if you specify "newelement" for the value parameter and there is already an element with the id attribute of 'newelement", the new element that the execCommand parameter adds will be "newelement0". If there are several elements with the same id attribute, for example, "newelement", "newelement0", and "newelement1", then the newly added element will increment up to the next available number, which in this case would be "newelement2".

Many of the commands used by the execCommand method require that the user select text in the page window in Microsoft FrontPage. If no text is selected and the command requires selected text, the execCommand method will fail and display an error.

Applies to | FPHTMLDocument Object | IHTMLDocument2 Object | IHTMLTxtRange Object