[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

Using Word/Excel SendKeys command from Delphi

Hi

I'm stuck and would really appreciate your help. How can you use Word's Sendkeys from Delphi?

I can't seem to make it work... I tried to do something similar with Excel. It doesn't work either :-(

Thank you very much in advance!

Regards,
Jay

var WordApp, WordDoc: Variant;
Begin
   WordApp := CreateOleObject('Word.Application');
   WordDoc:=WordApp.Documents.Open(FileName:=FN);
   WordApp.SendKeys ('Hello', True);
   ...
   WordApp.Quit;
end;
0
jaygan
Asked:
jaygan
1 Solution
 
GrahamSkanCommented:
The best advice about Sendkeys is "don't".

This will add text at the beginning ot the document. It defines more precisely what you want to do, and is less likely to b patched to avoid the obvious security hole.

   WordApp := CreateOleObject('Word.Application');
   WordDoc:=WordApp.Documents.Open(FileName:=FN);
   WordDoc..Range(0,0).Text = "Hello";
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now