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

    • VeryGut
      By VeryGut
      I'm trying to insert the following formula in cell A2 using my script:
      =if(A1=""; "YES"; "NO")
      To my understanding, the line of code should be similar to this:
      _Excel_RangeWrite($MasterFile, Default, "=if(A1=""; "YES"; "NO")", "A2")
      However, it does not work, probably due to the multiple quotation marks that confuse the script :C
      How do I avoid this problem?
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have a question about Excel, i have to create several charts one below the other dynamically.
      I have thought to use:
       
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count  
      And then to use it in this way:
      $Graph_position = "=Test1!A"&$iRowCount+2&":K"&$iRowCount+24 But it doesn't work with charts.
      Does anyone have a suggestion?
       
    • Patryk
      By Patryk
      Dear Colleagues,
      I have no idea how to refer to style.display in my loop. There is a button like: 
      <input name="ctl00$bodyPlaceholder$btnFecharProcessamento" class="button" id="bodyPlaceholder_btnFecharProcessamento" style="display: none;" onclick="FecharJanelaProcessamento();return false;" type="submit" value="Fechar"> I want it to be clicked as soon as button's style change from style="display: none;" to  style= ="display: inline-block;" 
      This is what I got, but it's not working...
      Func GetButtons() $oButtons = _IEGetObjByName($oForm,"ctl00$bodyPlaceholder$btnFecharProcessamento",-1) $i = 0 While $i <> 1 For $oBtn In $oButtons If _IEFormElementGetValue($oBtn) = "Fechar" And $oBtn.document.style.display = "display: inline-block;" Then $i = 1 _IEAction($oBtn, "focus") _IEAction($oBtn, "click") ExitLoop EndIf Next WEnd EndFunc  
      I will really appreciate if you could help me with these loop!
    • LoneWolf_2106
      By LoneWolf_2106
      Hi all,
      i have an empty csv file, i have a non formatted text file.
      What do i want to do?
      I want to automate the process "get external data" in Excel, i want to import the data from the text file and basically create a csv file with a specific character encoding.
      Is it possible with AutoIT?
       
    • breakbadsp
      By breakbadsp
      I  want to create a excel file from my script if it does not exist.
      _ExcelBookOpen throws error=2 if file does not exist, after this error i want to create new file at this point.
      can i use _FileCreate()?
      _Logger($sLogPath, "{INFO}------: Opening Excel File: " & $sExcelPath& "") While 1 Local $oExcelTestResult = _ExcelBookOpen($sExcelPath) If @error = 2 Then If not _FileCreate($sResExcelPath) Then MsgBox(0, "Error", "Error In Opening REsult Excel File: Error: " & String(@error)) _Logger($sLogPath, "{ERROR}------: Result Excel File does not exist.. tried to create new but :ERROR : " & String(@error) & "") ExitLoop Else _Logger($sLogPath, "{INFO}------: Result Excel File does not exist.. **Created New**: ") EndIf Else ExitLoop EndIf WEnd