-1

I'm trying to copy some cells from Microsoft Excel to another program using AutoIt, but I can just copy one cell at a time. Is there a way to copy a group or range of cells?

My code:

Local $Resultcpf = Excel_RangeRead($oWorkbook, default, "L4")

ClipPut($Resultcpf)
$Data = ClipGet()
user4157124
  • 2,809
  • 13
  • 27
  • 42

2 Answers2

0

"Is there a another way to copy a group of range?"

As per Documentation - User Defined Function Reference - _Excel_RangeRead() :

Reads the value, formula or displayed text from a cell or range of cells of the specified workbook and worksheet

Example :

#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <Excel.au3>

Global Const $g_sFileDoc = 'C:\document.xlsx', _
             $g_sRange   = 'L:L', _; 'L1:L4'
             $g_sPrompt  = 'Press [CTRL] + [V] to paste contents of %s.'

Global       $g_oExcel   = _Excel_Open(), _
             $g_oBook    = _Excel_BookOpen($g_oExcel, $g_sFileDoc)
Global       $g_aData    = _Excel_RangeRead($g_oBook, Default, $g_oBook.ActiveSheet.Usedrange.Columns($g_sRange))
Global       $g_sData    = _ArrayToString($g_aData)

_ArrayDisplay($g_aData)
ClipPut($g_sData)
MsgBox($MB_SYSTEMMODAL, @ScriptName, StringFormat($g_sPrompt, $g_sRange))
user4157124
  • 2,809
  • 13
  • 27
  • 42
0

You have to define the range by B3:C5 for two columns or A1:A17 for one column and so on. The range has to be divided by colon ":" sign.

#include-once
#include <Array.au3>
#include <Excel.au3>

Global $sFileExcel  = @DesktopDir & '\MyExcelSheet.xlsx'
Global $sExcelRange = 'B3:C5'

Func _readExcelContent()
    Local $oExcel    = _Excel_Open()
    Local $oWorkbook = _Excel_BookOpen($oExcel, $sFileExcel)
    Local $aData     = _Excel_RangeRead($oWorkbook, Default, $sExcelRange, 2)
    _Excel_Close($oExcel, Default, True) ; excel will be closed
    Return $aData
EndFunc

Global $aData = _readExcelContent()
_ArrayDisplay($aData) ; this is just a preview of the read data

ClipPut(_ArrayToString($aData))

The result/output could be :

text1|
text2|text4
text3|

Depending on Excel content of course.

user4157124
  • 2,809
  • 13
  • 27
  • 42