I typically work with the Office family's data in OLE mode.
First, the definition
Wordapp:variant;
Currdoc:variant;
Selection:variant;
Second, initialize
Wordapp.visible: = true;
Currdoc: = WordApp.documents.Open (Afullfilename, Revert: = True, Visible: = True);
Selection: = currdoc.activewindow.selection;//advantage is not afraid to open and close other Word documents and error
III. Release Processing
If not Varisempty (Currdoc) Then
Begin
Try
Currdoc.save;
Currdoc.close;
Except
End
End
Currdoc: = Unassigned;
If not Varisempty (WordApp) Then
Begin
Try
Wordapp.quit;
Except
End
End
WordApp: = Unassigned;
Selection: = Unassigned;
The above is the basic treatment.
Five, the VBA to Delphi processing method
First please download my other Post's Office VBA manual for easy reference.
Here are just a few examples of how to convert from VBA code to Delphi code.
This part is VBA code
Debug.Print Selection.Information (Wdendofrangecolumnnumber) ' 17 End column
Debug.Print Selection.Information (Wdendofrangerownumber) ' 14 End line
Debug.Print Selection.Information (wdstartofrangecolumnnumber) ' 16 Start column
Debug.Print Selection.Information (wdstartofrangerownumber) ' 13 Start line
Delphi Code:
Bcol: = selection.information[16];//where Selection is defined, look ahead to have and VBA similar
Ecol: = Selection.information[17];//information This is the property of Selection. VBA is used () but is used in Delphi []
Brow: = selection.information[13];//Call Property has arguments when Delphi is [],vba is () function or event all is ()
Erow: = selection.information[14];
VBA turns into Delphi a lot of parts can be copied, but there are subtle differences. Pay attention to this.
Six, my application to read the current cursor is in the table that position, but Word's table data read, very troublesome.
I used this to deal with it.
Selection.paragraphs.item (1). Range.Text: = ";
From VBA to Delphi