这是偶的代码,请批评指导
procedure WordDocumentDeletePage(var WordApp: Variant; var WordDoc: Variant; PageIndex: Integer);
begin
if VarIsEmpty(WordApp) then
Exit;
if VarIsEmpty(WordDoc) then
Exit;
if PageIndex < 1 then
Exit;
WordDoc.Activate;
WordDocumentSelectPage(WordApp, WordDoc, PageIndex);
WordApp.Selection.Delete;
end;
procedure WordDocumentDeletePages(var WordApp: Variant; var WordDoc: Variant; StartPage, EndPage: Integer);
var
NumberOfPages: Integer;
begin
if VarIsEmpty(WordApp) then
Exit;
if VarIsEmpty(WordDoc) then
Exit;
NumberOfPages := WordDocumentGetNumberOfPages(WordApp, WordDoc);
// if StartPage = -1 then
// StartPage := 1;
// if EndPage = -1 then
// EndPage := NumberOfPages;
if EndPage < 1 then
Exit;
if StartPage > NumberOfPages then
Exit;
if StartPage > EndPage then
Exit;
if StartPage < 1 then
StartPage := 1;
if EndPage > NumberOfPages then
EndPage := NumberOfPages;
if StartPage > EndPage then
StartPage := EndPage;
WordDoc.Activate;
WordDocumentSelectPages(WordApp, WordDoc, StartPage, EndPage);
WordApp.Selection.Delete;
end;
procedure WordDocumentSelectPage(var WordApp: Variant; var WordDoc: Variant;
PageIndex: Integer);
var
Range1, Range2: Variant;
NumberOfPages: Integer;
begin
if VarIsEmpty(WordApp) then
Exit;
if VarIsEmpty(WordDoc) then
Exit;
NumberOfPages := WordDocumentGetNumberOfPages(WordApp, WordDoc);
if NumberOfPages = 0 then
Exit;
if PageIndex < 1 then
Exit;
if PageIndex > NumberOfPages then
Exit;
Range1 := WordDoc.goto(wdGotoPage, wdGoToAbsolute, PageIndex);
Range2 := Range1.GoToNext(wdGotoPage);
if Range2.Start = Range1.Start then
Range2.Start := WordDoc.Range.End;
WordDoc.Range(Range1.Start, Range2.Start).Select;
end;