對word之bookmark插入字串如何攔錯 |
缺席
|
pceyes
尊榮會員 發表:70 回覆:657 積分:1140 註冊:2003-03-13 發送簡訊給我 |
<textarea class="delphi" rows="10" cols="60" name="code">procedure TForm1.Button1Click(Sender: TObject);
const
// Word Document to open
// Dein Word Dokument
YourWordDocument = 'c:\test\worddoc.doc';
var
BookmarkName, Doc, R: OleVariant;
begin
// Start a Word instance
// Word Instanz Starten
try
WordApp := CreateOleObject('Word.Application');
except
ShowMessage('Could not start MS Word!');
end;
// Open your Word document
// Dok. öffnen
WordApp.Documents.Open(YourWordDocument);
Doc := WordApp.ActiveDocument;
// name of your bookmark
// Name der Textmarke
BookmarkName := 'MyBookMark';
// Check if bookmark exists
// Überprüfen, ob Textmarke vorhanden
if Doc.Bookmarks.Exists(BookmarkName) then
begin
R := Doc.Bookmarks.Item(BookmarkName).Range;
// Add text at our bookmark
// Text bei Textmarke einfügen
R.InsertAfter('Text bei Textmarke');
// You make a text formatting like changing its color
// Man kann nun auch den Text formatieren. z.B die Farbe wechseln.
R.Font.Color := clRed;
end;
</textarea><br />
以上的碼是指將字串插入ms-word的bookmark中, 請問如果使用者自行關閉word時, 會發生例外情形, 請問程式如何攔截其錯誤訊息,以便進一步處理,謝謝。
------
努力會更接近成功 |
eaglewolf
資深會員 發表:4 回覆:268 積分:429 註冊:2006-07-06 發送簡訊給我 |
以你的程式來說
使用者根本沒機會 看到 word ( 少了WordApp.Visible := True; 這行) 更遑論 要關閉它 撇開這個不談 如果是因為user關閉 word 還是可以用 try .... except 來攔截 會產生EOleSysError 的系統錯誤 錯誤訊息是 [無法取得RPC服務] ===================引 用 pceyes 文 章=================== <textarea class="delphi" rows="10" cols="60" name="code">procedure TForm1.Button1Click(Sender: TObject); const // Word Document to open // Dein Word Dokument YourWordDocument = 'c:\test\worddoc.doc'; var BookmarkName, Doc, R: OleVariant; begin // Start a Word instance // Word Instanz Starten try WordApp := CreateOleObject('Word.Application'); except ShowMessage('Could not start MS Word!'); end; // Open your Word document // Dok. ffnen WordApp.Documents.Open(YourWordDocument); Doc := WordApp.ActiveDocument; // name of your bookmark // Name der Textmarke BookmarkName := 'MyBookMark'; // Check if bookmark exists // berprfen, ob Textmarke vorhanden if Doc.Bookmarks.Exists(BookmarkName) then begin R := Doc.Bookmarks.Item(BookmarkName).Range; // Add text at our bookmark // Text bei Textmarke einfgen R.InsertAfter('Text bei Textmarke'); // You make a text formatting like changing its color // Man kann nun auch den Text formatieren. z.B die Farbe wechseln. R.Font.Color := clRed; end; </textarea><br /> 以上的碼是指將字串插入ms-word的bookmark中, 請問如果使用者自行關閉word時, 會發生例外情形, 請問程式如何攔截其錯誤訊息,以便進一步處理,謝謝。
------
先查HELP 再查GOOGLE 最後才發問 沒人有義務替你解答問題 在標題或文章中標明很急 並不會增加網友回答速度 Developing Tool: 1.Delphi 6 2.Visual Studio 2005 3.Visual Studio 2008 DBMS: MS-SQL |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |