Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Help with SENDKEYS?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed - 05 Jun 2007 16:57 GMT
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
Karl E. Peterson - 05 Jun 2007 17:58 GMT
> 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
[quoted text clipped - 4 lines]
>
> Any help or suggestions are greatly appreciated.

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

.NET: It's About Trust!
http://vfred.mvps.org

yves@champollion.net - 05 Jun 2007 21:13 GMT
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
yves@champollion.net

> > 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
[quoted text clipped - 20 lines]
> .NET: It's About Trust!
>  http://vfred.mvps.org
Ed - 05 Jun 2007 22:43 GMT
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

On Jun 5, 1:13 pm, y...@champollion.net wrote:
> Yes, SendKeys should be a last resort. But last resorts are used as
> last resort so here we go.
[quoted text clipped - 35 lines]
> Yves Champollion
> y...@champollion.net
alborg - 06 Jun 2007 14:48 GMT
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

> > 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
[quoted text clipped - 17 lines]
>
> Sendkeys should *always* be the method of last resort.  HTH!
Karl E. Peterson - 06 Jun 2007 17:27 GMT
> Karl is right- the SendKeys method tends to be querky.

Worse still are the apparent problems with it under Vista!

  http://www.google.com/search?q=vb+sendkeys+vista

I did a simple test, using both VB5 and VB6, and it appeared to work in that case.
But it sure looks like it's heartburn-waitin'-to-happen in most.
Signature

.NET: It's About Trust!
http://vfred.mvps.org

alborg - 08 Jun 2007 03:50 GMT
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

> > Karl is right- the SendKeys method tends to be querky.
>
[quoted text clipped - 4 lines]
> I did a simple test, using both VB5 and VB6, and it appeared to work in that case.
> But it sure looks like it's heartburn-waitin'-to-happen in most.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.