Get the value of selected text (outside of Excel)?

  • Thread starter Thread starter Internetdomainowner
  • Start date Start date
I

Internetdomainowner

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!
 
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
 
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







- 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!
 
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 %
 
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 %





















- Show quoted text -

Well thanks for trying... it's a shame that there isn't a straight
foward approach to using WM_GETTEXT...
 
I may be willing to dive in with you an try to figure it out
I also do VBScripting and there are alot of great methods with it that are
more intrinsic to Windows as opposed to the particular app, as with VBA.

So tell me, what does WM_GETTEXT stand for?
Is that Windows Management?

I have a feeling that crawling techniques are what is used by hackers and
such to get passwords etc.; I'm not sure though, as I am not a hacker.
Well, I hack my own code but that is about it :)

So, tell me the definition and where did you get started?
Was it a Google Search?

ML
 
OK
I did a Google search.
This link is stright from Microsoft's Web Page
While it is an interesting concept, you are correct, it doesn't look very
stright forward or well explained.
ML

http://msdn.microsoft.com/en-us/library/aa922085.aspx







- Show quoted text -

It's the oddest thing... there is no specific "Starters Guide to
WM_GETTEXT or WM_SENDTEXT... I feel like I did when to a Roman
Catholic wedding (not trying to offend anyone, as I am Christian) --
but that feeling is I'm familar with what's going on but generally
lost with how to do the 'traditions'.

I almost want to start a thread called "WM_GETTEXT / WM_SENDTEXT for
Newbies/Dummies". I found some app that allows me to view the Control
ID (which I assume is the same as me saying UserForm1.Textbox1.Value)
but still there is no answer as to how to use this code or how to
implement it to do something like send the value of textbox1.value to
Control ID titled "text1".

What's amazing is something that is useful as this isn't explained
very well... it's going to be a whole new world if this is explained
by some genious.
 
It's the oddest thing... there is no specific "Starters Guide to
WM_GETTEXT or WM_SENDTEXT... I feel like I did when to a Roman
Catholic wedding (not trying to offend anyone, as I am Christian) --
but that feeling is I'm familar with what's going on but generally
lost with how to do the 'traditions'.

I almost want to start a thread called "WM_GETTEXT / WM_SENDTEXT for
Newbies/Dummies". I found some app that allows me to view the Control
ID (which I assume is the same as me saying UserForm1.Textbox1.Value)
but still there is no answer as to how to use this code or how to
implement it to do something like send the value of textbox1.value to
Control ID titled "text1".

What's amazing is something that is useful as this isn't explained
very well... it's going to be a whole new world if this is explained
by some genious.- Hide quoted text -

- Show quoted text -


Hope this gets answers... I'm even offering to pay someone to explain
this process... I don't even know how anyone ever learned how to use
this code correctly.

http://groups.google.com/group/micr.../browse_thread/thread/b25e38531b704588?hl=en#

http://groups.google.com/group/micr.../browse_thread/thread/b25e38531b704588?hl=en#
 

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

Back
Top