SendKeys Question

I have inherited a worksheet that has some macros that were coded in Excel 2003 and uses the line

SendKeys "+{TAB}", -1

I am using Excel 2010 now and the code is malfunctioning and I belive it has to do with that line. I belive the +Tab is to shift to the next cell to the left but I do not know what the -1 is for. I have tried searching for what the -1 is supposed to do but cannot find it. Can anyone tell me what it is for? Thanks!
MistbornAsked:
Who is Participating?
 
MistbornAuthor Commented:
Sid,

Thanks for your help, I just figured out what was wrong! The shift+tab was not working beacuse some of the cells needed to be locked and had gotten unlocked causing it to not skip over cells that it needed to. The -1 must just default to a false and had nothing to do with the actual problem but it had me on the right track. Thanks again for the assistance.
0
 
SiddharthRoutCommented:
The syntax of Sendkeys is

Sendkeys String,Wait

From Excel's Help

Sends one or more keystrokes to the active window as if typed at the keyboard.

Syntax

SendKeys string[, wait]

The SendKeys statement syntax has these named arguments:

Part Description
string Required. String expression specifying the keystrokes to send.
Wait Optional. Boolean value specifying the wait mode. If False (default), control is returned to the procedure immediately after the keys are sent. If True, keystrokes must be processed before control is returned to the procedure.

Sid
0
 
MistbornAuthor Commented:
Thanks for he reply but I am still confused. It says that the -1 should be setting a wait mode...but what is the wait mode that the -1 sets it to?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
SiddharthRoutCommented:
It has to be 0 or 1 and not -1

or best to use True/False

Change the code to

SendKeys "+{TAB}", True

Sid
0
 
Rory ArchibaldCommented:
Even better, don't use sendkeys if possible as it is not that reliable. If it is just being used to select another cell, it's unnecessary anyway, but can you post the code so we can see exactly what it's doing?
0
 
SiddharthRoutCommented:
You are welcome :)

Sid
0
 
MistbornAuthor Commented:
Copying the help file didn't really help at all.
0
 
modus_operandiCommented:
Mistborn,

It appears that you resolved the problem yourself, albeit with some help from the Experts, and so while your comment will be marked with the answer Sid and rorya will share in the points.

In any event, the original C grade was wholly unwarranted; it should typically be reserved for cases where the Expert(s) gave vague and incomplete answers and then failed to reply to reasonable requests for clarification.

FWIW, I know a thing ir two about Excel, and rorya's advice to avoid SendKeys is best practice.  Also, -1 does NOT convert to False in VBA.  -1 is boolean True, 0 is boolean False, and in a type conversion any non-zero numeric value converts to the True.
 
modus_operandi
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.