Methods
Constructor.CreateNewDoc(WordApp : TWordApp; Template : String);
Constructor.CreateOpenDoc(WordApp : TWordApp; FileName : String);
Constructor.CreateFromComDoc(WordApp : TWordApp; ComDoc : _Document);
Constructor.CreateFromActiveDoc(WordApp : TWordApp);
These create new TWordDoc objects. They will automatically add themselves to the WordApp list of documents. If you are using the event sink, you should not need to create documents from the active document as TWordApp will create TWordDocs from any documents that are present in Word in its constructor and will also create TWordDocs from any document that is opened in Word by the user (i.e., it will keep itself up-to-date). Also, in this situation, CreateFromComDoc should not be needed either for the same reason (both are used internally).
Destructor.Destroy; override;
Destructor.CloseDoc(oeSaveChanges: TOleEnum);
These methods will free the TWordDoc object. The simple destructor will not close the document in Word (so that the user can continue to edit it and save it himself). The destructors will remove the WordDoc object from its parent WordApp list and will also clear up any range objects associated with this document.
Print;
PrintPrview;
Rudimentary print routine. See TWordApp.PrintActiveDoc for more
information.
Standard PrintPreview command.
UpdateFields;
SaveAs(Filename : String);
Fairly obvious methods
UpdateFullname;
The property Fullname is the name and path of the document. It is usually kept up-do-date when the document is opened and saved. However, if the user saves the document directly, TWordDoc will not be in sync. You can use this method to get the current COM objects's Fullname property. When a fresh document is created it is usually given a name like "Document1".
AddRangeFromBookMark(BookmarkName : String) : TWordRange;
AddRangeFromSelection : TWordRange;
AddRangeFromDoc(iStart : Integer = 1; iEnd : Integer = 1) : TWordRange;
AddRangeFromRange(ComRange : Range) : TWordRange;
DeleteRange(Index : Integer);
These methods allow you to add to and delete ranges. These just call the Creator methods of TWordRange. They should be fairly self-explanatory. AddRangeFromDoc's parameters are measured in characters. It is really just a means of getting a TWordRange object (esp if you omit the parameters). You can then move the range to where you want to using TWordRange methods. AddRangeFromRange sounds a bit odd but is a means of getting a TWordRange object from a given COM range object.
AddCustomProperty (Index: String; Value : Variant;
oePropertyType : TOleEnum);
AddCustomProperty(Index: String; Value : String);
overload; // delphi 4-5 only
DeleteCustomProperty(Index: String);
Add/delete a custom property -you need to "use" the office type library (Office97.pas in Delphi 5 & Office_TLB.pas in Delphi 3-4) to get the constants for oePropertyType
Alternatively for Delphi 4-5 you can use the overloaded method when Value can be String, Integer, Double, TDateTime & Boolean
ReplaceBookmark (BookmarkName, ReplaceText : String; ReassignBookmark : Boolean = True);
This is a quick way of replacing a bookmarked entry with text. ReassignBookmark determines whether to reassign the new range with the original bookmark name (normally the bookmark is lost after such a text replacement).
RemoveBookmark (BookmarkName : String);
RemoveBookmarkByIndex (Index : Integer);
Allows you to remove a bookmark by name or index (useful for iterative purposes)
NoOfPages (IncludeFootnotesAndEndnotes : Boolean = False) : Integer;
NoOfWords (IncludeFootnotesAndEndnotes : Boolean = False) : Integer;
Fairly obvious functions.
GoTo_(oeWhat, oeWhich : TOleEnum; oeCount: Integer = 1; oeName: String = '') :
Range;
GoToNext(oeWhat : TOleEnum) : Range;
GoToPrevious(oeWhat : TOleEnum) : Range;
These Goto... functions move the document's selection object. NB selection objects are slow - use ranges. Also, I haven't tried moving a document's selection when it is not the active document (I suspect you may get an exception as I think Word only has one selection object at any one time - I may be wrong). The functions return COM range objects. You can treat the functions as procedures and throw away the returned COM object or you could combine these with AddRangeFromRange to get a TWordRange object.
Properties
WordApp : TWordApp read FWordApp;
The parent TWordApp that owns the TWordDoc object.
Fullname : String read FFullname;
The same as the COM object Document.Fullname property. However TWordDoc stores this internally so you don't actually need the COM object to be there to read it. This is useful in the OnClose event where Word has already got rid of the COM document object (so you can't get at it). You could reload the file if the user "accidentally" closed it. Note that TWordApp and TWordDoc try to keep this up-to-date but cannot catch all situations where the COM object's fullname has changed (e.g., if the user saves the document himself within Word). You can use UpdateFullname to re-sync things if you suspect this may have happened. Do not use UpdateFullname in an OnClose event (the COM object has gone - you will get an exception).
Active : Boolean read GetActive write SetActive;
Indicates/sets whether the document is the visible active document in Word.
AutoTextEntries : OleVariant read GetAutoTextEntries;
This returns an OleVariant for you to use. For some reason the Word type library does not go as far as providing the Document's AttachedTemplate propertyit only returns an OleVariant from the function Get_AttachedTemplate. I can think of no reason for this as templates are defined in the type library and you can get a list of them from the Application object. You will have to use this property as you would any late bound object.
Mode : TWordDocMode read FMode;
One of three things (wdmCreating, wdmExisting, wdmDestroying) to indicate whether the object is in the middle of being created or destroyed
DocStillInWord : Boolean;
True of the TWordDoc object's COM document is still present in Word (i.e., the user hasn't closed it behind your back). Only really a problem if you are not using the event sink as you will get a suitable close event in that case.
Document : _Document;
This returns the actual COM _Document object.
Range [Index: Integer] : TWordRange;
NoOfRanges : Integer;
These properties allow you to retrieve ranges, usually for iterative purposes.
BookmarkByIndex [Index: Integer] : Word_TLB.Bookmark;
Bookmark [BookmarkName: String] : Word_TLB.Bookmark;
BookmarkExists : Boolean;
NoOfBookmarks : Integer;
These properties allow you to get access to the bookmark collection of the document.
ItemIndex : Integer;
Returns the index of the TWordDoc object within the TWordApp list.
BuiltInProperty [Index : TOleEnum] : Variant;
Get or set a built in property - you need to "use" the office type library (Office97.pas in Delphi 5 & Office_TLB.pas in Delphi 3-4) to get the constants for Index.
CustomProperty [Index : String] : Variant;
Get or set a custom property - note this property must already exist (either add it using Word or using the method AddCustomProperty).
RTF : String;
Get or set the entire Word document as Rich Text Format.