View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
ML0940 ML0940 is offline
external usenet poster
 
Posts: 47
Default Get the value of selected text (outside of Excel)?

Oh God
I think you are asking if you copy text from any place, such as a web page?
It is an interesting idea, only I am not sure it is possible.
I think there is a technique called crawling but I am not familiar with it.
I thought that you were looking for something very specific, such as a
variable that you wanted to pass to another app.

I would only use Sendkeys if there is no other way as well but looking at
your code, it doesn't look like you did Ctrl C and Ctrl V correctly.

I have tried it but this is from The Excel-VBA help screen:

ML

To specify keys combined with any combination of the SHIFT, CTRL, and ALT
keys, precede the key code with one or more of the following codes:
Key Code
SHIFT +
CTRL ^
ALT %


" wrote:

On Jul 20, 7:11 pm, ML0940 wrote:
That is a good questionn and I am going to say yes; as long as the value is
assigned to variable; in this case, a string variable.
I pass code between AutoCAD and Excel with no problem, so it the code can
get to the other app, then I'm sure it can be read by a textbox in the
receiving app.
I have read lines of text from a .txt file into a list box in ACAD, so that
certainly can be done.

Can you be a little more specific as to what you are trying to do?
Besides Excel, what is the other app?

ML



" wrote:
Fellow programmers,


This one is driving me up a wall... Is it possible to get the value
of selected text on another program as the value of a textbox on a
userform? If so, how is this done? I've looked into the some API code
for GetWindowText and WM_GETTEXT but I have been very unsuccessful
very quickly. Any thoughts? I appreciate any feed back available.


Thank you in advance!- Hide quoted text -


- Show quoted text -


Say I was working inside of internet explorer and I wanted to
essentially have selected text using the mouse appear as a value in a
textbox on a userform... now before anyone suggests having CTRL + C
and CTRL + V as a result -- I am not looking to go down that avenue as
it doesn't work... I've tried using the Windows API to select text
based on mouse cordinates (x, z) and using the sendkeys commands to
copy the value of the selected text and try to paste in a textbox on a
userform... it doesn't work. Someone can try the very same code if
they would like...


Private Sub Commandbutton1_Click()
SetCursorPos 255, 413

DoEvents
Application.Run "mouscoords"
'------------------ mosecoords grabs the current mouse cordinates

mouse_event MOUSEEVENTF_LEFTDOWN, 0&, 0&, 0&, 0&
'------------------ API to press the left mouse button on those cords

Do Until UserForm1.TextBox1.Value = 520
'------------------ Have the macro stop when the x value = 520

UserForm1.TextBox1.Value = UserForm1.TextBox1.Value + 5
'------------------ Figure the average character size (font size 10)
is going to be 5 pixels wide

SetCursorPos UserForm1.TextBox1.Value, 413
'------------------- Textbox1.value is the X cordinate +5 the old one

DoEvents
'------------------ Update the textboxes and continue running until
end IF statement works
Loop

mouse_event MOUSEEVENTF_LEFTUP, 0&, 0&, 0&, 0&
'------------------ Release the mouse button

Application.Wait Now +TimeValue("00:00:01")
'------------------- Wait for the system to refresh

SendKeys "^C", True
'------------------- Copy the selected text value

Application.Wait Now +TimeValue("00:00:01")
'------------------- Wait for the system to refresh

Userform1.Textbox3.SetFocus
'------------------- Set focus to the textbox I want the value to put
into

SendKeys "^V", True
'------------------- Paste the selected text value

For whatever reason the code doesn't work... So I am hoping to venture
down the road of being able to have the system say "the selected text
is the following value..." in a textbox on a userform.

Any help is greatly appreciated!