Jump to content
Sign in to follow this  
ShrutiW

Copy Pasting Excel cell value to application

Recommended Posts

Can I paste a value copied from a cell in the excel sheet to the text box in an application? using like ClipGet() or any other functions?  Is it possible?

Here's the code that I've tried so far. 

Local $oRange = $oWorkbook.ActiveSheet.Range("A1:R1")  ; Reading excel sheet
_Excel_RangeCopyPaste($oWorkbook.ActiveSheet, $oRange, "E1")  ;copying value from cell "E1"
 Local $sData = ClipGet()
WinWait ("New Contact","")     ; Activating the window of application where I want to paste the cell value
WinActivate("New Contact","")
WinWaitActive("New Contact")
Sleep(2000)
ControlGetHandle("New Contact",ClipGet() , "[CLASS:ThunderRT6TextBox ; INSTANCE:6]")     ;TextBox where I want to paste the copied value

 

Share this post


Link to post
Share on other sites

No need to use _Excel_RangeCopyPaste. Simply use _Excel_RangeRead to read the cell value to a variable and then use ControlSend to"paste" the value to the other application.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Hi @water,

I tried using ReadRange, didn't get result . Please have a look at the code.  

Local $aResult = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:R"), 1)
 Local $sResult = _Excel_RangeRead($oWorkbook, Default, "E2")
 WinWait ("New Contact","")
 WinActivate("New Contact","")
 WinWaitActive("New Contact")
 Local $hWnd = WinWait("New Contact","")
 Sleep(2000)
 ControlSend($hWnd,$sResult ,"[CLASS:ThunderRT6TextBox ; INSTANCE:6]" , "")

What changes are expected?

Share this post


Link to post
Share on other sites

@ShrutiW

ControlSend ( "title", "text", controlID, "string" [, flag = 0] )

- Title: the title/hwnd of the window where the control exists;

- Text: the text of the window where the control exists (you can leave it blank);

- ControlID: the control ID/handle/text... of the control, in order to interact with it;

- String: the string to send to the control;

- Flag: how to send the string:

- Use $SEND_DEFAULT (0) to send special characters like + or !, which are respectively Shift and Alt key presses;

- Use $SEND_RAW (1) to send the text as is to the control.

Switch your second parameter with the fourth one in the ControlSend function, and you should be done :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

What's the return value of ControlSend?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Hi @water, I have used $sResult variable to store the value in the cell, and I am passing "$sResult" as a return value in control send. Is it a right way to do? 

Share this post


Link to post
Share on other sites

You need to define "not desired result".
Do you get no text in the control, the wrong text (e.g. characters missing, wrong encoding) or do you get an error?
To check for an error you need to have a look at the return value:

$iReturnValue = ControlSend($hWnd,"","[CLASS:ThunderRT6TextBox ; INSTANCE:6]" ,$sResult)
If $iReturnValue <> 1 Then MsgBox(0, "Error!", "window/control is not found!")

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Hi @water, I checked with above code,I do not get any text in the control.  Got an error message box.

windowControl.PNG

Edited by ShrutiW

Share this post


Link to post
Share on other sites

The error message describes what happens:
Either the window or control could not be found.
As the window handle has been derived from a WinWait it seems that the control could not be found.
Searching for "ThunderRT6" shows a lot of threads describing problems with this type of controls. Maybe one of them sheds some light onto the subject and delivers a solution?

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Hi @water, It is not working in either way, It is getting in over my head now.😥 Is there any other way I can retrieve cell values from excel and send them to text boxes and combo boxes in a windows application? 

Share this post


Link to post
Share on other sites

You should try SimpleSpy from UIAutomation (you can find more here) :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

The part about reading Excel values has been solved.
If your application provides an API for automation I would use this and drop automating the GUI. Have a look at the documentation of your application and see if you find something about COM, API or programming.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...