display copied text by a msgbox in VB

Hello everybody , how are you.
I have some tasks , in which i am facing some problems.Plz help.

(1)I wish to display the copied text(clipboard) by a msg box,dunno what is the syntax for it in VB.
For example i have copied A and i want to display it by msgbox.

(2)Also i wish to compare or check this text with some another text.
For example i have copied text EDUCATION and i wish to compare it with the word SCHOOL and if the copied text is SCHOOL the VB programme will stop else it will process.Plz also guide where i should define the word SCHOOL in the VB programme.

(3)While sending keystrokes to another window , how can i implement the WAIT key between the respective keystrokes.Plz guide the SYNTAX for WAIT key.
For example i have sent keystrokes A and ENTER and now i wish the VB programme to wait for some time(in sec on millisec) so that the required result is displayed and then furthermore keystrokes may now be sent.PLz guide the syntax.

Thanks in advance.
Thank you.

step back

lets take a step back... what are you actually trying to do?

wish to automate a process


the purpose is to automate a process.

In which one of the step is to compare copied text with SCHOOL and second step id to display the copied text by a msgbox..Thats why i hav copied the text first but i dunno how to compare it with the word school.Perhaps i think i should use read command so that it will automatically search the word SCHOOL, i m lil bi confused , wht to do , plz help.

Nick's picture

copied text

is there any reason why you need to copy the text to the clipboard ?

i.e. if the idea is top copy range("A1") , why not display range("A1")  ?


msgbox  range("A1")



text to be retrived from another window

hello ,
the text that i wish to compare or match needs to be retrived from another window , i thought first the text will be copied to computer memory(clipboard), from there we can match it with our string word or is there any command by which the VB script can directly read text from that window.
Let us hav an example.
For eg.we have opened YAHOOMAIL web page and we wish to compare the text "Sign in to Yahoo!".Firstly we can copy this in clip board and then compare it or we can make a VB code which will directly read this line .
Plz also guide syntax for wait key.

Thank you

Nick's picture


Wait 10 seconds:

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10 ' change this
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

RE getting data from the web,  take a look at this article:




revert-WAIT key

thanks NICK ,

the code u gave for wait key is working but not at that time when i want.

For eg. i wish to implement the wait key after step 1 in the following code.

Sub CommandButton1_Click()

step 1 :Img1.Pictuce = 1.gif

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10  ' change this
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

step 2 :Img1.Picture = 2.gif

End Sub

But when i am  running the code the wait code is implemented first and then step 1 and 2 are executed wthout wait.It means the code is waiting be4 starting the programme not at the moment where i want.

Thanks in advance

Nick's picture



hi Ruth

SendKeys is not a great way of doing things..

If you give more detail maybe we can find the proper way



you are right

hi nick , u r very right , u just said what i was tinking from last one week.
Sendkey is also not a good way even for sending keystrokes ,cos sometimes it sends some keystrokes and sometimes it misses out.Is there any other method for sending keystrokes on another application.Can u plz suggest.
If not can we make sure while sending keys(sendkey method) that the first sendkey is processed correctly or not and then another sendkey will start processing.Perhaps we may not need WAIT key if this is possible.
Waiting for ur reply.
Thanks in advance.

Nick's picture


my last suggestion for getting sendkeys to work is to put the line: DoEvents before your sendKeys code....



Alternative to sendkeys

plz provide any alternative to sendkeys .Sendkeys are not working properly .i wish to send some keystrokes on another application already opened at the desktop.Sendkeys are not reliable for this.

Plz help