I'm trying to write a script that should read a value from the clipboard, look for this value in an Excel spreadsheet,
and then if the value is found, the entire line where the value was found should be copied to the clipboard.
Here what I've found/written so far:
Code: Select all
#NoEnv
#Persistent
#SingleInstance,Force
#x::
{
Clipboard:="" ; clear clipboard
Send, ^c ; Marked text is copied to clipboard
PXL := ComObjGet("C:\MyFolder\test.xlsx")
;Find_And_Return_Position
XL_Find_And_Return_Position(PXL,RG:="",Search:="%clipboard%",Absolute:=0,Instance:=1){
RG:=(RG)?(RG):(XL_Used_RG(PXL,0)) ;If Range not provided, default to used range
Index:=0
For Cell in PXL.Application.ActiveSheet.Range(RG) { ;Use For loop to iterate over each cell in range
if Cell.Value=(Search) { ;Stop looping if you find the value
Index++ ;Increment Index
If (Index=Instance){ ;If this is the correct instance
if Absolute
Return Cell.address ;;~ Cell with $ in them
Else Return Cell.address(0,0) ;;Cell without $ in them
/*
Return Absolute?Cell.Address:Cell.Address(0,0)
*/
}}
} Return "Not found" ;If finish looping then it was not found
}
;Copy_to_Clipboard
XL_Copy_to_Clipboard(PXL,RG:="%Cell.address%"){
PXL.Application.ActiveSheet.Range(Cell.address).Copy ;copy to clipboard
}
}
who can help, many thanks in advance