Jump to content

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

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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?

Link to comment
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

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

What's the return value of ControlSend?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...