The application SendKeys

J

Jim333

Hi everybody,

My question is about using the application SendKeys with IF inside VBA,
I have a table contains twenty rows and five columns (File Attached),
what I want is that when any of the twenty cells in column "C" is not
blank, Then: By using the application SendKeys, the current date should
be inserted in the opposite cell in column "D".

I have created a code for that purpose, but it did not work properly,
so I wish I could find the answer in this wonderful site.

And this is the code I have created:

PRIVATE SUB WORKSHEET_CHANGE(BYVAL TARGET AS RANGE)
IF RANGE("C" & TARGET.ROW).VALUE <> "" THEN
RANGE("D" & TARGET.ROW).VALUE = APPLICATION.SENDKEYS("^;")
EXIT SUB
END IF
END SUB


+-------------------------------------------------------------------+
|Filename: SendKeys.zip |
|Download: http://www.excelforum.com/attachment.php?postid=3695 |
+-------------------------------------------------------------------+
 
G

Guest

First: Application.SendKeys does not give you a value you can assign to a
range, as you are trying to do; instead you would need to make the desired
cell the active cell and then use SendKeys to type the string "^;" into it,
but...

Next point: it is not necessary or even advisable to use SendKeys for this;
just get today's date with the Date() function:
IF RANGE("C" & TARGET.ROW).VALUE <> "" THEN
RANGE("D" & TARGET.ROW).VALUE = DATE()
 
J

Jim333

Hi,

Thank you for your reply, but the code you delivered is not what I want
excalty. The date updates daily while I want it to stay as it was
inserted at the first time and that is why I asked to insert it by
using SendKyes Application.

Do you have another way???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top