Avatar billede xenoxsis Nybegynder
25. februar 2008 - 15:43 Der er 14 kommentarer og
1 løsning

Hjælp til SendKeys - Kopiering

Hej Alle,

Jeg sidder med en opgave hvor jeg skal bruge access til at hente noget tekst fra et andet program. Jeg bruger følgende kode:

SendKeys ("%{TAB}")

PauseTime = 1
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop

SendKeys ("%R")
SendKeys ("A")

PauseTime = 1
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop

SendKeys ("^(C)")

Det den skal er at TAB'e over til mit andet program. Gå ind i Rediger menuen, Trykke A (for så at markere alt) og trykke CTRL + C for at kopiere det markerede til mit clipboard. Jeg ved at jeg kan gøre det manuelt så den del virker. Og med det her system går den over, får markeret det hele og så forsvinder markeringen (Dette sker også når jeg manuelt kopierer) - Men når jeg så går over i notepad eller lign så har den ikke kopieret noget.

Er der nogen der kender grunden til dette eller har en bedre løsning?
Avatar billede terry Ekspert
26. februar 2008 - 19:33 #1
Isnt there a risk that the program you TAB over to isnt the one where your data is?

What are the Timer delays for, the do events might have something to do with your problem,
Avatar billede xenoxsis Nybegynder
26. februar 2008 - 21:32 #2
I have ways to test that I am at the right program. So that shouldnt present a problem. But to make it easier, do you know how to check the title of the active window through VBA?
The timer delays are to halt the sendkeys, so if there is some "lag" in the program i'm switching to. So the timers give me program time to load before sending the next "batch" of keys.
Avatar billede terry Ekspert
26. februar 2008 - 22:06 #3
"..  how to check the title of the active window through VBA?"

Do you mean active form? Well if you are executing code in a form then
me.caption

but I have a feeling that this isnt what your after.
Avatar billede xenoxsis Nybegynder
26. februar 2008 - 22:08 #4
No the active window - nevermind. The real problem is actually the CTRL + C not working. It's really annoying cause I just can't see any reason why it shouldn't work.
Avatar billede terry Ekspert
26. februar 2008 - 22:14 #5
Forms in Access arent the same as windows in other applications.

I havent tried what you are trying to do, but shouldnt your SendKeys ("A")

be a CTRL+A like your  CTRL+C ? > SendKeys ("^(A)")

Also the doevents, I would have thought that this would take the focus away from yoru other application.
Avatar billede terry Ekspert
26. februar 2008 - 22:22 #6
Avatar billede xenoxsis Nybegynder
26. februar 2008 - 22:43 #7
No because:

SendKeys ("%{TAB}")
' Tabs over to the program

SendKeys ("%R")
' ALT + R opens the edit (I think) menu (Called Rediger in danish)

SendKeys ("A")
' Uses the select all part of the menu (Marker Alt) which actually selects everything
' on the screen in this program.

SendKeys ("^(C)")
' Should then copy this text so I can put it in my database and begin extracting
' information from the text.
Avatar billede terry Ekspert
27. februar 2008 - 18:53 #8
Have you tries the link I gave previously?

Here is an alternative to SendKeys
http://www.mvps.org/access/api/api0046.htm
Avatar billede xenoxsis Nybegynder
28. februar 2008 - 07:41 #9
The link is about SendKeys turning off Numlock? Did I miss the connection to what i'm doing?
Avatar billede terry Ekspert
28. februar 2008 - 11:15 #10
Have you read the NOTE? For example>
"..This is because the keystrokes are processed by whichever window is currently active on the desktop."


And also
"So, simply put, try to avoid Sendkeys at all cost. "
Avatar billede xenoxsis Nybegynder
28. februar 2008 - 17:33 #11
Ahh I didnt read the note - sorry.

It couldn't avoid sendkeys sadly if I was to do what I was/am doing...
Avatar billede terry Ekspert
28. februar 2008 - 19:11 #12
Waht program are you trying to copy data from?
Avatar billede xenoxsis Nybegynder
29. februar 2008 - 00:20 #13
Its a custom coded very old program at my work. So I couldn't name it, cause I simply dont know the name of it really :)
Avatar billede terry Ekspert
29. februar 2008 - 16:57 #14
Maybe ist time to replace it which will maybe remove the need for using sendkeys. Or maybe it is possible to alter the program so what ever your trying to copy to Access is done from there.
Avatar billede xenoxsis Nybegynder
04. april 2008 - 10:54 #15
Well the program is a program bought for a very large company and can therefore not be changed. I guess I'd have to scram that idea alltogether. Thank you for trying to help.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester