SkysLastChance

_Excel_RangeRead Loop Error

10 posts in this topic

#1 ·  Posted

I am not sure why I am getting the this error on my second pass of the code.

1 - $oWorkbook is not an object or not a workbook object

Any help or advice on my code appreciated. 

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

Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)")
Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)")
Global $vRow = 2

If FileExists($sExcelFile2) Then
   Global $oExcel2 = _Excel_Open ()
    $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2)
EndIF

If FileExists($sExcelFile1) Then
   Global $oExcel1 = _Excel_Open ()
    $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007")
EndIF


$oRead = _Excel_RangeRead ($oExcel2,"Untitled","A2",3)
$oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92",Default,$xlWhole)
$Clip = _ArrayToClip($oFind,"",0,0,"",2,2)


Send("{ScrollLock Off}")
$hWnd = WinWait("[CLASS:XLMAIN]")
ControlSend($hWnd, "", "", ("^g"))
WinWait("[CLASS:bosa_sdm_XL9]") ; Go To
ControlSend($hWnd, "", "", ("^v"))
ControlSend($hWnd, "", "", ("{Enter}"))
ControlSend($hWnD, "", "", "{Down " & $vRow & "}")

Do

$oTime  = _Excel_RangeRead ($oExcel2,"Untitled","B2",3)

If @error Then Exit MsgBox(0, "Error", "Error" & @CRLF & "@error = " & @error & ", @extended = " & @extended)


MsgBox(0,"Test",$oTime)

IF $oTime = "7:10:00 AM" Then
   $oCalls1 = _Excel_RangeRead ($oExcel2,Default,"C" & $vRow,3)
   $oCalls2 = _Excel_RangeRead ($oExcel2,Default,"D" & $vRow,3)
   ControlSend($hWnd, "", "", $oCalls1)
   ControlSend($hWnd, "", "", ("{RIGHT}"))
   ControlSend($hWnd, "", "", $oCalls2)
   $vRow = $vRow + 1
   ContinueLoop
Else
   $vRow = $vRow + 1

EndIf

Until $vRow = 4

1.xlsm

2.xlsx


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites



#2 ·  Posted

Maybe because you use variables $oExcel1 / $oExcel2 to hold the application AND the workbook object.
Example:

If FileExists($sExcelFile2) Then
   Global $oExcel2 = _Excel_Open ()
    $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2)
EndIF

BTW: There is no need to call _Excel_Open two times. Call _Excel_Open after starting the script once and use the returned application object to open both workbooks.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Thank you!

This is how I changed it. I hope this is what you meant.

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

Global $vRow = 2

Local $oExcel = _Excel_Open()
Local $sWorkbookx = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)")
Local $oWorkbookx = _Excel_BookOpen($oExcel, $sWorkbookx)
Local $sWorkbookm = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)")
Local $oWorkbookm = _Excel_BookOpen($oExcel, $sWorkbookm,Default,Default,"2007")



$oRead = _Excel_RangeRead ($oWorkbookx,"Untitled","A2",3)
$oFind = _Excel_RangeFind ($oWorkbookm,$oRead,"E4:FD92",Default,$xlWhole)
$Clip = _ArrayToClip($oFind,"",0,0,"",2,2)

Send("{ScrollLock Off}")

Local $hWnd = WinWait("[CLASS:XLMAIN]")
ControlSend($hWnd, "", "", ("^g"))
WinWait("[CLASS:bosa_sdm_XL9]") ; Go To
ControlSend($hWnd, "", "", ("^v"))
ControlSend($hWnd, "", "", ("{Enter}"))
ControlSend($hWnD, "", "", "{Down " & $vRow & "}")

Do

$oTime = _Excel_RangeRead($oWorkbookx,Default,"B2",3)

MsgBox(0,"Test",$oTime)

IF $oTime = "7:10:00 AM" Then
   $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vRow,3)
   $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vRow,3)
   ControlSend($hWnd, "", "", ("^v"))
   ControlSend($hWnd, "", "", ("{Down}"))

   ;ControlSend($hWnd, "", "", $oCalls1)      ;
   ;ControlSend($hWnd, "", "", ("{RIGHT}"))   ;
   ;ControlSend($hWnd, "", "", $oCalls2)      ;
   $vRow = $vRow + 1
   ContinueLoop
Else
   $vRow = $vRow + 1

EndIf

Until $vRow = 4

The script works fine now until I add. 

$oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vRow,3)
  $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vRow,3)
  
  ControlSend($hWnd, "", "", $oCalls1)      ;
  ControlSend($hWnd, "", "", ("{RIGHT}"))   ;
  ControlSend($hWnd, "", "", $oCalls2)      ;

 


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites

#4 ·  Posted

What do you mean by "The script works fine now until I add."?
Please describe as detailed as possible what you expect and what you get. Any error messages etc. ...?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

Do you not specify a ControlID on purpose?
If you specify the ControlID you can drop the

ControlSend($hWnd, "", "", ("{RIGHT}"))

statement.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

Sorry for not being more clear. My poor code dose not help either.

So, as you probally expected the code was doing exactly what it was supposed to do. It was just not working how I wanted it to. LOL 

Thank you for your patients @Water

I fixed this as well. 

ControlSend($hWnd, "", "EXCEL72", $oCalls1)
   ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
   ControlSend($hWnd, "", "EXCEL72", $oCalls2)

I am starting to think this is not even going to work for what I want it to do.  :/

I am going to keep playing around with it though. 

 


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites

#7 ·  Posted

I have it working they way I want now. 

I was just wondering is there a way to make this faster?

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

Global $hWnd,$oExcel,$sWorkbookx,$oWorkbookx,$sWorkbookm,$oWorkbookm,$oExcelm,$oExcelx

Excel ()


AMSeven  ()
AMEight  ()
AMNine   ()
AMTen    ()
AMEleven ()
PMTwelve ()
PMOne    ()
PMTwo    ()
PMThree  ()
PMFour   ()
PMFive   ()
PMSix    ()

Func Excel ()
   $oExcel = _Excel_Open()
   $sWorkbookx = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)")
   $oWorkbookx = _Excel_BookOpen($oExcel, $sWorkbookx)
   $sWorkbookm = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)")
   $oWorkbookm = _Excel_BookOpen($oExcel, $sWorkbookm,Default,Default,"2007")
   $oExcelm = _Excel_BookAttach($oWorkbookm)
   $oExcelx = _Excel_BookAttach($oWorkbookx)
   Local $oRead = _Excel_RangeRead ($oWorkbookx,"Untitled","A2",3)
   Local $oFind = _Excel_RangeFind ($oWorkbookm,$oRead,"E4:FD92",Default,$xlWhole)
   Local $Clip = _ArrayToClip($oFind,"",0,0,"",2,2)
   Send("{ScrollLock Off}")
   $hWnd = WinWait("[CLASS:XLMAIN]")
   ControlSend($hWnd, "", "EXCEL72", ("^g"))
   WinWait("[CLASS:bosa_sdm_XL9]") ; Go To
   ControlSend($hWnd, "", "", ("^v"))
   ControlSend($hWnd, "", "", ("{Enter}"))
   ControlSend($hWnD, "", "", "{Down 2}")
EndFunc

Func AMSeven ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "7:00:00 AM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Func AMEight ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "8:00:00 AM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Func AMNine ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "9:00:00 AM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Func AMTen ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "10:00:00 AM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Func AMEleven ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "11:00:00 AM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Func PMTwelve ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "12:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc






Func PMOne ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "1:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc


Func PMTwo ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "2:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc


Func PMThree ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "3:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc


Func PMFour ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "4:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc


Func PMFive ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "5:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc


Func PMSix ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "6:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Global $hWnd,$oExcel,$sWorkbookx,$oWorkbookx,$sWorkbookm,$oWorkbookm,$oExcelm,$oExcelx

Excel ()


AMSeven  ()
AMEight  ()
AMNine   ()
AMTen    ()
AMEleven ()
PMTwelve ()
PMOne    ()
PMTwo    ()
PMThree  ()
PMFour   ()
PMFive   ()
PMSix    ()

Func Excel ()
   $oExcel = _Excel_Open()
   $sWorkbookx = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)")
   $oWorkbookx = _Excel_BookOpen($oExcel, $sWorkbookx)
   $sWorkbookm = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)")
   $oWorkbookm = _Excel_BookOpen($oExcel, $sWorkbookm,Default,Default,"2007")
   $oExcelm = _Excel_BookAttach($oWorkbookm)
   $oExcelx = _Excel_BookAttach($oWorkbookx)
   Local $oRead = _Excel_RangeRead ($oWorkbookx,"Untitled","A2",3)
   Local $oFind = _Excel_RangeFind ($oWorkbookm,$oRead,"E4:FD92",Default,$xlWhole)
   Local $Clip = _ArrayToClip($oFind,"",0,0,"",2,2)
   Send("{ScrollLock Off}")
   $hWnd = WinWait("[CLASS:XLMAIN]")
   ControlSend($hWnd, "", "EXCEL72", ("^g"))
   WinWait("[CLASS:bosa_sdm_XL9]") ; Go To
   ControlSend($hWnd, "", "", ("^v"))
   ControlSend($hWnd, "", "", ("{Enter}"))
   ControlSend($hWnD, "", "", "{Down 2}")
EndFunc

Func AMSeven ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "7:00:00 AM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Func AMEight ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "8:00:00 AM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Func AMNine ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "9:00:00 AM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Func AMTen ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "10:00:00 AM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Func AMEleven ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "11:00:00 AM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

Func PMTwelve ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "12:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc






Func PMOne ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "1:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc


Func PMTwo ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "2:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc


Func PMThree ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "3:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc


Func PMFour ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "4:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc


Func PMFive ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "5:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc


Func PMSix ()

Local $vCalls = 2
Local $vTime  = 2
Local $vCount = 0
Local $vTrigger = 0

Do

Local $oTime = _Excel_RangeRead($oWorkbookx,Default,"B" & $vTime,3)

IF $oTime <> "6:00:00 PM" Then
      $vTime  = $vTime  + 1
      $vCount = $vCount + 1
      $vCalls = $vCalls + 1

Else

Local $oCalls1 = _Excel_RangeRead ($oWorkbookx,Default,"C" & $vCalls,3)
Local $oCalls2 = _Excel_RangeRead ($oWorkbookx,Default,"D" & $vCalls,3)
    ControlSend($hWnd, "", "EXCEL72", $oCalls1)
    ControlSend($hWnd, "", "EXCEL72", ("{Right}"))
    ControlSend($hWnd, "", "EXCEL72", $oCalls2)
    ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
    ControlSend($hWnd, "", "EXCEL72", ("{Left}"))
 $vCalls = $vCalls + 1
 $vTime  = $vTime  + 1
   ExitLoop
EndIF

Until $vCount = 14

If $vCount = 14 Then
   ControlSend($hWnd, "", "EXCEL72", ("{Down}"))
EndIF

EndFunc

 

 

The only date this code will find is 6/19/2017 (In A2 of Sheet 2.) This code does not work if I have a different date in A2. If I put 6/26/2017 it will not find anything. 

I figured it has to be something to do with the way it is formated in excel, However from what I can tell they are formated the same. 

When I read the cells they (6/19/17) and (6/26/17) both on sheet 2.  They display the same information.

When I _Excel_RangeFind it works when I have 6/19/2017 in A2. But if I switch to any other date. It will not find anything. 

Everything needed to test script is in my original post.

I could really use some help on this. 

 

Edited by SkysLastChance
Added Code

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites

#9 ·  Posted

Go figure I solved my problem right after I post. 

I fixed it by copy and pasting the dates again and redoing the merge and center for all of them.

I still have no idea why it wasent working though. :/


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites

#10 ·  Posted

Maybe you stored the dates as strings and by using copy & paste Excel interpreted them as dates?
Nevermind: Glad the problem could be solved!

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - 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

  • Similar Content

    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have to store an entire row of a Excel workbook into an array.  The row index is stored in a variable.
      How can i do it?
      Thanks in advance for your support.
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have to write a value into an excel column.
      I know where it starts from, but i don't know what the end is, last non-empty cell.
      How can i get the number of last non-empty cell?
      Thanks in advance.
      Regards 
    • Nareshm
      By Nareshm
      Hi All,
      I have excel file like this
      and i want to cut cell/text from excel to other software.

       
      I have to cut the cell of B column one by one and past into other software
      If Winexists("No Data Found")
      then restore cuted cell and goto next/down side cell
      How to do it ?
    • Nareshm
      By Nareshm
      How to repeat my script when my control class does not match ?
       
      My Script : winActivate ( " PS :: Version - 2.2.0.0  - [PS Bill]")                   ControlClick ( "PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]")                   ControlSend(" PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]", "{enter}")                   WinActive ("Verification Number Entry ::")                   ControlClick("Next >", "","[NAME:btnNext]") ;if   >>>> Control <<<<  does not match repeat my script, ;if match exit script  

      Class:    WindowsForm734a
      Instance:    15
      ClassnameNN:    WindowsForm34a15
      Name:    BillPrint
      Advanced (Class):    [NAME:BillPrint]
      ID:    7875
      Text:    
      Position:    39, 310
      Size:    1221, 306
      ControlClick Coords:    745, 20
      Style:    0x56010000
      ExStyle:    0x00000000
      Handle:    0x00000000000C0468
    • water
      By water
      Extensive library to control and manipulate Microsoft Excel charts.
      Theads: General Help & Support - Example Scripts
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2017-07-21)
      None. The COM error handling related bugs have been fixed.