[SOLVED] MS Word: move text cursor to the end of the document lazarus / 21-General ---------------------------------------------------------------------- w click · 2022-11-19 17:49 I've hit a snag where I simply can't find the magic code to make this work.  I'm in Windows and wordapp and sourcedoc are olevariant. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure OpenWord(s:string); begin  if fileexists(s) then begin    try      try        WordApp:=CreateOleObject('Word.Application');      except      showmessage('Unable to start Word.');      end;      sourcedoc:=wordapp.Documents.Open(WideString(utf8decode(s)));    //      Move cursor to the end of the document goes here.       WordApp.Visible:=True;  {Make WordApp visible}    except      showmessage('It all went pear-shaped.');    end;  end else showmessage(s+' does not exist.');end;           I've tried all sorts of weird ideas, but none have worked.  The document opens fine.  Can anyone help, please? ---------------------------------------------------------------------- mtrsoft · 2022-11-19 21:41 This may be of some help Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure wdDocGoToEnd( AwdApp :WordApplication; AExtendSelection :Boolean = False);beginAwdApp.Selection.EndKey( wdStory, AExtendSelection);end;  If needed I can expand on the definitions of the parameters. Regards, John ---------------------------------------------------------------------- w click · 2022-11-20 11:38 It worked, as soon as I'd looked up the parameters.  Thanks John. I used: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i wordapp.Selection.EndKey(6,false); Where do you find proper documentation on this? ---------------------------------------------------------------------- Thaddy · 2022-11-20 12:03 MSDN ? https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop. word.selection.endkey?view=word-pia Since FPC can support this through a type libaray or late binding, such reference should always be looked up on MSDN. If you are confused I can help you, but translation to Pascal is really straightforward. ---------------------------------------------------------------------- w click · 2022-11-20 12:35 You are right to sigh.  I've never been able to work out how to translate that (and other sites) into Pascal and simply end up confused. The next elements to achieve are to move up-a-line and then go to the end-of-line. ---------------------------------------------------------------------- mtrsoft · 2022-11-20 19:15 @wclick, Attached are a couple of files with additional functions and definitions of their parameter values. Hope this helps. Regards, John ---------------------------------------------------------------------- w click · 2022-11-21 11:30 Thank you, I shall have a gander.