Jump to content

Question regarding Copy and Paste


aic2011
 Share

Recommended Posts

We wrote a script to copy and paste value from Excel table. Is it possible to end that command if the value copied on the excel table is null or empty? So We are running a while loop to copy and paste from cell 1, cell 2, cell 3 etc and if cell 4 is empty or has no value, end the while loop. So it needs to read the copied value and see if it is null or empty and decide based on that. Any ideas on how we should do that?

Link to comment
Share on other sites

Here you go. Thanks for helping.

While 1
If ClipGet() <> "" Then
Send("{ALT DOWN}{TAB}{ALT UP}")
_WinWaitActivate("Microsoft Excel - newOrder","")
Send("{DOWN}")
Send("^c")
Send("{ALT DOWN}{TAB}{ALT UP}")
_WinWaitActivate("R7CPQ6 @ (365)","")
Send("^v")
Send("{ENTER}")
Send("{ENTER}")
EndIf
If ClipGet() = "" Then
    ExitLoop
Send("{ALT DOWN}{TAB}{ALT UP}")
_WinWaitActivate("Microsoft Excel - newOrder","")
Send("{DOWN}")
Send("^c")
Send("{ALT DOWN}{TAB}{ALT UP}")
_WinWaitActivate("- R7CPQ6 @  (365)","")
Send("^v")
Send("{ENTER}")
EndIf
WEnd

- the clipget() = "" does not exit the loop.

Edited by aic2011
Link to comment
Share on other sites

You may want to look into using the "ExcelCOM_UDF.au3" or at least the "Excel.au3"; would make things a lot easier.

#include <ExcelCOM_UDF.au3>

Local $eFile = "" ;Excel file to open
Local $oExcel = _ExcelBookOpen($eFile,0,True)       ;Excel File, Not Visible, Read Only
If Not @error = 1 Or Not @error = 2 Then            ;1=can't create Excel Object, 2=File not found
    _ExcelSheetActivate($oExcel,1)                  ;Excel Variable for file open, specified sheet
    Local $eValue, $eRow = 1      
    Do
        $eValue = $oExcel.Cells($eRow,1).Value      ;Sets $eValue to specified row, column 1 value
        If $eValue = "" Then ExitLoop               ;Cell is empty
        
        ;Put coding in for what you want to do with the $eValue here
        
        $eRow += 1                                  ;go to next row
    Until $oExcel.Cells($eRow,1).Value = ""         ;Row is empty
Else      
    ; Message for Excel not found/opened
EndIf
_ExcelBookClose($oExcel)                            ;Close your Excel file

That should be a fairly good example to get you started

Edit: Here's a link to the AU3 files mentioned

Edited by Country73

If you try to fail and succeed which have you done?AutoIt Forum Search

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...