ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   The application SendKeys (https://www.excelbanter.com/excel-programming/337364-application-sendkeys.html)

Jim333[_6_]

The application SendKeys
 

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 |
+-------------------------------------------------------------------+

--
Jim333
------------------------------------------------------------------------
Jim333's Profile: http://www.excelforum.com/member.php...fo&userid=5186
View this thread: http://www.excelforum.com/showthread...hreadid=396075


K Dales[_2_]

The application SendKeys
 
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()
--
- K Dales


"Jim333" wrote:


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 |
+-------------------------------------------------------------------+

--
Jim333
------------------------------------------------------------------------
Jim333's Profile: http://www.excelforum.com/member.php...fo&userid=5186
View this thread: http://www.excelforum.com/showthread...hreadid=396075



Jim333[_7_]

The application SendKeys
 

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???


--
Jim333
------------------------------------------------------------------------
Jim333's Profile: http://www.excelforum.com/member.php...fo&userid=5186
View this thread: http://www.excelforum.com/showthread...hreadid=396075



All times are GMT +1. The time now is 07:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com