ActiveDocument Object

Use the ActiveDocument object to refer to the document currently displayed in the editor. To access an open document that is not active, use the Application.DocumentCache object.

Properties

CanRedo

Syntax

CanRedo: WordBool (read-only) 

Description

Boolean. Returns True if changes can be re-done.

Example

function Main() {
var sMessage;

sMessage = "CanRedo : ";

with (Application) {
     If(ActiveDocument.CanRedo)
        sMessage = sMessage + "Yes";   
     Else 
        sMessage = sMessage + "No";
     
   MessageBox(sMessage, VersionText, 0);  

}
}

CanUndo

Syntax

CanUndo: WordBool (read-only) 

Description

Boolean. Returns True if changes can be undone.

Example

function Main() {
var sMessage;

sMessage = "CanUndo : ";

with (Application) {
     If(ActiveDocument.CanUndo)
        sMessage = sMessage + "Yes";   
     Else 
        sMessage = sMessage + "No";
     
   MessageBox(sMessage, VersionText, 0);  
}
}

CaretPosX

Syntax

CaretPosX: integer (read-only) 

Description

The X-axis caret position.

Example

function Main(){
  with (Application){
    if (ActiveDocument.CaretPosX > 1){
      ActiveDocument.CursorLineStart(false);
    }
  }
}

CaretPosY

Syntax

CaretPosY: integer (read-only) 

Description

The Y-axis caret position.

Example

function Main(){
  with (Application){
    if (ActiveDocument.CaretPosY > 1){
      ActiveDocument.CursorDocStart(false);
    }
  }
}

Filename

Syntax

Filename: OleString (read-only) 

Description

File name of the active document.

Example

function Main() {
var sMessage;

sMessage = "Your file name is: ";

with (Application) {
     
     sMessage = sMessage + ActiveDocument.Filename;

     MessageBox(sMessage, VersionText, 0);  
}
}

LineCount

Syntax

LineCount: integer (read-only 

Description

Number of lines in the active document.

Example

function Main() {
var sMessage;

sMessage = "Your file line count is: ";

with (Application) {
     sMessage = sMessage + ActiveDocument.LineCount;
     MessageBox(sMessage, VersionText, 0);
}
}

Lines

Syntax

Lines(Index: integer) OleString 

Description

Gets and sets the text of the line at the passed index. Iterating through a document using the Lines property might be slow, especially for large documents. For best results, only use Lines to evaluate single lines of text. If you must use Lines to update many lines, you can increase performance by wrapping the update in a BeginUpdate..EndUpdate block.

Example

function Main(){
  with (Application){
    ActiveDocument.Lines(0) = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
  }
}

Modified

Syntax

Modified: WordBool (read-only) 

Description

Boolean. Returns True if the document changed since it was last saved.

Example

function Main() {
var sMessage;

sMessage = "Modified : ";

with (Application) {
     If(ActiveDocument.Modified)
        sMessage = sMessage + "Yes";   
     Else 
        sMessage = sMessage + "No";
     
   MessageBox(sMessage, VersionText, 0);  
}
}

ReadOnly

Syntax

ReadOnly: WordBool (read-only) 

Description

Boolean. Returns True if the active document is read-only.

Example

function Main(){
  with (Application){
    if (ActiveDocument.ReadOnly){
      MessageBox('Current document is Read-Only', 'Information', 0);
    }
  }
}

SelStart

Syntax

SelStart: integer 

Description

Gets and sets the start of the current selection.

Example

function Main(){
  with (Application){
    with (ActiveDocument){
      // Select entire document
      SelStart = 0;
      CursorDocEnd(true);
    }
  }
}

SelLength

Syntax

SelLength: integer 

Description

Gets and sets the length of the current selection.

Example

function Main() {
var sMessage;

sMessage = "The length of the selected text of your document is ";

with (Application) {
     sMessage = sMessage + ActiveDocument.SelLength;
     MessageBox(sMessage, VersionText, 0);
}
}

SelText

Syntax

SelText: OleString 

Description

Gets and sets the text in the current selection.

Example

function Main() {
var sMessage;

sMessage = "The length of the selected text of your document is ";

with (Application) {
     sMessage = sMessage + ActiveDocument.SelText;
     MessageBox(sMessage, VersionText, 0);
}
}

TabIndex

Syntax

TabIndex 

Description

Gets and sets the tab index of the document tab.

Example

function Main(){
  with (Application){
    if (ActiveDocument.TabIndex != 0){
      DocumentIndex = 0;
    }
  }
}

Text

Syntax

Text: OleString 

Description

Gets and sets the complete document text.

Methods

BeginUpdate

Syntax

BeginUpdate(); 

Description

Turns off screen updating for the active document. This is useful if your script needs to make several changes to the active document at once-turning off screen updating during the procedure might significantly speed up the process. To turn on updating again, use EndUpdate.

Use BeginUpdate...EndUpdate with caution. If you fail to call EndUpdate after a call to BeginUpdate, or if the script crashes before EndUpdate is called, the user cannot view any changes made in the editor.

Clear

Syntax

Clear(); 

Description

Clears all text from the active document.

Close

Syntax

Close(wbPromptToSave: WordBool): WordBool;  

Description

Boolean. Closes the active document. If wbPromptToSave is True, the user is prompted to save any changes. Returns True if the document was closed (that is, the user didn't cancel saving changes).

Cursor

Syntax

Cursor_ (wbSelect: WordBool); 

Description

Boolean. Positions the cursor. If wbSelect is True, then the current selection is extended to the new cursor position.

The following values are allowed:

CursorLeft, CursorRight, CursorWordLeft, CursorWordRight, CursorDown, CursorUp, CursorPageDown, CursorPageUp, CursorDocStart, CursorDocEnd, CursorLineStart, CursorLine End.

Example

function Main(){
  with (Application){
    // Select the entire line
    ActiveDocument.CursorLineStart(false);
    ActiveDocument.CursorLineEnd(true);
  }
}

EndUpdate

Syntax

EndUpdate(); 

Description

Turns on screen updating for the active document.

Example

function Main(){
  var iTags = 0;
  with (Application){

    ActiveDocument.BeginUpdate();
    ActiveDocument.CursorDocStart(false);

    try{
      while (ActiveDocument.GotoNextStartTag(false)){
        iTags++;
      }
      
    }
    finally{
      ActiveDocument.EndUpdate();
    }
    
    MessageBox('Total tags: ' + iTags, 'Tag Count', 0);
  }
}

GetCaretPos

Syntax

GetCaretPos(var x, y: integer); 

Description

Returns the caret pos (x=column, y=line).

GetCurrentChar

Syntax

GetCurrentChar(): OleVariant; 

Description

Returns the current character.

GetNextChar

Syntax

GetNextChar(): OleVariant;  

Description

Returns the next character. If you use this function, along with GetPreviousChar, in long loops, the code can run slowly.

GetPreviousChar

Syntax

GetPreviousChar(): OleVariant;  

Description

Returns the previous character.

GetTagAtCursor

Syntax

GetTagAtCursor(wbSelect: WordBool): WideString;  

Description

Boolean. Returns the tag in which the cursor is currently located in the editor. If a tag cannot be identified, the method returns an empty string.

If wbSelect is True, the tag is highlighted in the document.

Example

// Displays a message box with the current tag 
function Main() {
with (Application) {
MessageBox(ActiveDocument.GetTagAtCursor(false), 'Current Tag At Cursor', 0);
}
}

GotoNextEndTag

Syntax

GotoNextEndTag(wbSelect: WordBool): WordBool; 

Description

Boolean. Moves the next end tag, and selects it if wbSelect is True. Returns False if no tag found.

GotoNextStartTag

Syntax

GotoNextStartTag(wbSelect: WordBool): WordBool; 

Description

Boolean. Moves the next starting tag and selects it if wbSelect is True. Returns False if no tag is found.

GotoPreviousEndTag

Syntax

GotoPreviousEndTag(wbSelect: WordBool): WordBool; 

Description

Boolean. Moves the previous end tag and selects it if wbSelect is True. Returns False if no tag is found.

Example

function Main(){
  with (Application){
    ActiveDocument.GotoPreviousEndTag(false);
  }
}

GotoPreviousStartTag

Syntax

GotoPreviousStartTag(wbSelect: WordBool): WordBool; 

Description

Boolean. Moves the previous starting tag and selects it if wbSelect is True. Returns False if no tag is found.

Example

function Main(){
  with (Application){
    ActiveDocument.GotoPreviousStartTag(true);
  }
}

Indent

Syntax

Indent(); 

Description

Indents the current selection.

InsertTag

Syntax

InsertTag(sStartTag, sEndTag: OleVariant; wbOverwriteSelection: 
WordBool); 

Description

Boolean. Inserts the passed tag pair at the current cursor position, overwriting the selection if wbOverwriteSelection is True. The cursor is positioned between the start and end tags after this operation. If wbOverwriteSelection is False, the tags surround the current selection.

Example

function Main(){
  with (Application){
    ActiveDocument.CursorDocEnd(false);
    ActiveDocument.InsertTag('<a href="http://www.macromedia.com">', '</a>', true);
  }
}

InsertText

Syntax

InsertText(InsertStr: OleVariant; wbOverwriteSelection: WordBool); 

Description

Boolean. Inserts the passed string at the current cursor position. If wbOverwriteSelection is True, this function overwrites the selection.

LastSavedDate

Syntax

LastSavedDate(); 

Description

Returns the datetime value for the last save of the active document file.

Example

function Main(){
  with (Application){
    SetStatusText('Last save: ' + ActiveDocument.LastSavedDate());
  }
}

Print

Syntax

Print(wbNoPrompt: WordBool); 

Description

Boolean. Prints the active document. If wbNoPrompt is False, prompts the user for print settings.

Redo

Syntax

Redo(); 

Description

Performs a single redo operation.

Reload

Syntax

Reload(wbPromptToSave: WordBool); 

Description

Boolean. Reloads the active document. If wbPromptToSave is True, prompts the user to save changes.

ReplaceAll

Syntax

ReplaceAll(strSearch, strReplace: OleVariant; bMatchCase: WordBool): 
Integer; 

Description

Boolean. Replaces all occurrences of strSearch with strReplace, matching case if bMatchCase is True. Returns the number of replacements made.

Save

Syntax

Save: WordBool(); 

Description

Boolean. Saves changes to the active document. Returns True if successful.

SaveAs

Syntax

SaveAs(wsFileName: widestring): WordBool; 

Description

Boolean. Saves changes to the active document to the file specified in the wsFileName parameter.Returns True if successful.

If wsFileName is empty, the standard Save As dialog box displays. This function overwrites existing files, so use it with caution.

Example

function Main(){
  var sFile = '';
  
  // Insert a link and create the file in one step
  with (Application){
    sFile = InputBox('Add File Link', 'Enter a filename to create and link to:', sFile);

    if (sFile == ''){
      return;
    }
    
    ActiveDocument.InsertTag('<a href="' + sFile + '">', '</a>', false);
    NewDocument(true);
    ActiveDocument.SaveAs(CurrentFolder + '\\' + sFile);
  }
}

SelectAll

Syntax

SelectAll(); 

Description

Selects all the text in the active document.

SelectCurrentLine

Syntax

SelectCurrentLine(); 

Description

Highlights the current line.

SelectLine

Syntax

SelectLine(Index: Integer); 

Description

Highlights the passed line.

SetCaretPos

Syntax

SetCaretPos(x, y: Integer); 

Description

Sets the current column/line.

TextPosToEditorPos

Syntax

TextPosToEditorPos(var nPos:OleVariant):WordBool; 

Description

Boolean. Converts an index in a text string in a VBScript script to the corresponding editor position. Takes into account tabs and newlines, which count as two characters in the text but only as one in the editor. Returns the nPos parameter as an OleVariant, but its actual type is integer.

This method is only supported in VBScript.

Undo

Syntax

Undo(); 

Description

Performs a single undo operation.

Unindent

Syntax

Unindent(); 

Description

Removes the indent in the current selection.

Comments