Using Word/Excel SendKeys command from Delphi

Posted on 2007-07-21
Last Modified: 2013-11-25

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!


var WordApp, WordDoc: Variant;
   WordApp := CreateOleObject('Word.Application');
   WordApp.SendKeys ('Hello', True);
Question by:jaygan
    1 Comment
    LVL 76

    Accepted Solution

    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..Range(0,0).Text = "Hello";

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now