Help with SENDKEYS?

E

Ed

Can someone point me some help understanding how to use SENDKEYS?
Possibly with some examples?

I've tried a few different things, but nothing seems to work. One
thing perhaps is that SENDKEYS only works with the window that has the
focus, yes? And when I step through a VBA project, the VBE window has
the focus. yes?
From what I've seen, most say ther best help with SENDKEYS is "don't
use it!" Unfortunately, it looks like it may be about my only
solution. In my work environment, I can not download and use any
other suggested program. But I need to walk through and operate basic
menu commands in PDFs and web pages. Things like Find, Select, Copy,
activating hyperlinks and checkboxes / option buttons, etc.

Any help or suggestions are greatly appreciated.

Ed
 
K

Karl E. Peterson

Ed said:
I've tried a few different things, but nothing seems to work. One
thing perhaps is that SENDKEYS only works with the window that has the
focus, yes?

Yes, by definition.
And when I step through a VBA project, the VBE window has
the focus. yes?
Yes.

From what I've seen, most say ther best help with SENDKEYS is "don't
use it!" Unfortunately, it looks like it may be about my only
solution. In my work environment, I can not download and use any
other suggested program. But I need to walk through and operate basic
menu commands in PDFs and web pages. Things like Find, Select, Copy,
activating hyperlinks and checkboxes / option buttons, etc.

Any help or suggestions are greatly appreciated.

Sendkeys should *always* be the method of last resort. HTH!
 
Y

yves

Yes, SendKeys should be a last resort. But last resorts are used as
last resort so here we go.

You will get VBA help on SendKeys parameters, which I won't repeat
here.

As you mentioned, sent keys operate on the window that currently has
the focus. So you should

1. cycle through all opened windows,
2. grab the one you need by finding a keyword in its caption,
3. activate it
4. send the keys
5. issue a Doevents
6. get the focus back home.

Something like that:
= = = = = = = = = = = = = = =
For Each MyTask In Tasks
If InStr(MyTask.Name, "key word") > 0 Then
MyTask.Activate
WasActivated = True
End If
Next

If Not WasActivated Then
MsgBox "Window not found"
Exit Sub
End If

SendKeys "%f"
DoEvents

Application.Activate

= = = = = = = = = = = = = = =
Cheers,
Yves Champollion
(e-mail address removed)
 
E

Ed

Thank you, Yves.
SendKeys "%f"
DoEvents

I will have an object set to the file I am working with, so I presume
it won't be that difficult to activate its window. (Then again, I
probably ought to bring my lunch along for that one!)

When I have a string of SENDKEYS commands, does there need to be a
DoEvents after each one? For instance, this was supposed to search a
web page for a text string, tab to the checkbox next to it, and check
the box.

objIE2.Activate

SendKeys "^F", Wait
SendKeys "Clear checkboxes", Wait
SendKeys "{ENTER}", Wait
SendKeys "{ESC}", Wait
SendKeys "{TAB}", Wait
SendKeys " ", Wait

Ed
 
A

alborg

Hi Ed:

Karl is right- the SendKeys method tends to be querky. The only time I've
used it is in the Palm programming environment and once in MS Word when I
wanted to send information to OneNote, which as you know, is a great program
that continutes to lack VBA.

Here's how I used the SendKeys to sent off a Tab event-

strpath = "c:\program files\microsoft office\office11\onenote.exe"
strswitch = " /new C:\onenoteimport.one"
strcmd = strpath & strswitch
Shell strcmd, vbMaximizedFocus

TextBox2.Copy

strswitch = " /paste"
strcmd = strpath & strswitch
Shell strcmd, vbMaximizedFocus

SendKeys "%{TAB}", True

Application.Selection.SetRange Start:=Selection.Start,
End:=ActiveDocument.Content.End
Application.Selection.Copy

strswitch = " /paste"
strcmd = strpath & strswitch
Shell strcmd, vbMaximizedFocus

Cheers,
Al
 
A

alborg

I got that OneNote code to work, but without vba, I stopped my OneNote
development there. The SendKeys just wasn't enough... <sigh>. Microsoft
should just junk OneNote and place the tabs into MS Word.

Cheers,
Al
 

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