From VBA to Delphi

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.