線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2347
推到 Plurk!
推到 Facebook!

取得Word中的游標位置

尚未結案
adrain
一般會員


發表:39
回覆:28
積分:13
註冊:2004-07-27

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-18 15:44:09 IP:61.59.xxx.xxx 未訂閱
目前我正開發一套有關Dephi去執行Word,目前遇到一個困境就是如何用VBA的指令去取得目前游標所在的位置,或是有其它方式可達成這方面的需求,不知有哪位高手能指點我ㄧ番,謝謝!!
chris_shieh
高階會員


發表:46
回覆:308
積分:240
註冊:2004-04-26

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-21 17:42:04 IP:219.68.xxx.xxx 未訂閱
procedure TForm1.Button2Click(Sender: TObject);
var
  Word:TWordApplication;
  _Doc: _Document;
  colNo, lineNo:String;
  Template:OleVariant;
begin
  Word:=TWordApplication.Create(self);
  Word.AutoConnect:=True;
  Word.AutoQuit:=True;
  Word.Visible:=True;
  Template:='C:\test.doc';
  _doc:=Word.Documents.Open(Template,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
  Showmessage('Move cursor to position you want to show');  //go to the word window and move cursor to somewhere
  lineNo:=_Doc.ActiveWindow.Selection.Information[wdFirstCharacterLineNumber];
  colNo:=_Doc.ActiveWindow.Selection.Information[wdFirstCharacterColumnNumber];
  Showmessage('行: ' + lineNo + #10#13 +
              '欄: ' + colNo) ;
end;
如上, 所抓到的就是畫面中的資訊 發表人 - chris_shieh 於 2005/01/21 17:51:30
adrain
一般會員


發表:39
回覆:28
積分:13
註冊:2004-07-27

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-01-21 18:28:18 IP:61.59.xxx.xxx 未訂閱
謝謝chris_shieh大大的賜教,但是我還有一個疑慮就是游標目前所在的位置有沒有辦法去取得他的座標?因為我想藉由游標目前所在的位置,然後再移到下一行的桐一個位置去設定TabPosition 還是說有其他的方式可以達到相同的功能,可否再麻煩您跟我說明一下呢~~ 謝謝!!
chris_shieh
高階會員


發表:46
回覆:308
積分:240
註冊:2004-04-26

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-01-21 19:41:00 IP:218.167.xxx.xxx 未訂閱
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd10/html/woproInformation.asp 我猜你是想要這兩項 wdHorizontalPositionRelativeToPage Returns the horizontal position of the specified selection or range; this is the distance from the left edge of the selection or range to the left edge of the page measured in points (1 point = 20 twips, 72 points = 1 inch). If the selection or range isn't within the screen area, returns 1. wdVerticalPositionRelativeToPage Returns the vertical position of the selection or range; this is the distance from the top edge of the selection to the top edge of the page measured in points (1 point = 20 twips, 72 points = 1 inch). If the selection isn't visible in the document window, returns 1. @瞭解越多.懂得越少@ 發表人 - chris_shieh 於 2005/01/21 19:43:37
adrain
一般會員


發表:39
回覆:28
積分:13
註冊:2004-07-27

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-01-21 21:30:57 IP:61.59.xxx.xxx 未訂閱
沒錯,這就是我所要的東西,再次感謝chris_shieh大大的熱情的教導
系統時間:2024-04-29 4:00:38
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!