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

    • anusha
      By anusha
      Hi I have jus started using auto-it . Please correct me if I'm wrong.
      I need to read data from an input in text box and search in excel file and return value in next column of matched cell on GUI.
      I have written below code but i cannot use variable which has data stored. it works only when search string is hard coded.
      Please help out.
       
      Example()
      Func Example()
      Local $GuiMain = GUICreate("EXCEL TEST", 399, 180) ;creates main GUI
      ;~ Local $idOK = GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
      Local $iWidthCell = 70
      Local $idLabel = GUICtrlCreateLabel("PART NUMBER", 10, 30, $iWidthCell,50)
      Local $RUN_1 = GUICtrlCreateButton("OK", 70, 70, 85, 25)
      Local $Input_1 = GUICtrlCreateInput("PART NUMBER", 100, 20, 120, 20)
      Local $sMenutext = GUICtrlRead($Input_1, 1)
      GUISetState(@SW_SHOW, $GuiMain)

          While 1
          $MSG = GUIGetMsg()
          Select
              Case $MSG = $GUI_EVENT_CLOSE
                  Exit
              Case $MSG = $RUN_1
                  Local $oAppl = _Excel_Open()

      Local $sFilePath1 = "D:\Anu_WorkFolder\Components.xlsx"
      Local $oWorkbook = _Excel_BookOpen($oAppl, $sFilePath1, Default, Default, True)
      Local $aResult = _Excel_RangeFind($oWorkbook, $sMenutext , Default, Default, $xlWhole)
    • Nareshm
      By Nareshm
      How to Activate Opened Excel Windows Using Class not Tittle, Because Some time opened defferent excel that have different name.
      I Tried with
      Winactivate ("[CLASS:XLMAIN]") but not working
    • willichan
      By willichan
      Here is another one from my archives that filled a specific need.
       
      Here is the back story if you are interested.
       
      Keep in mind that I wrote this script over 3 years ago, so it may not compile or run directly without some minor tweaks.  It also requires the use of GraphViz to build the graph.
      #cs ---------------------------------------------------------------------------- Project Name: ExcelLinksMapper Description: Analyse an Excel file's links and map them out. Creation Date: 9/26/2014 AutoIt Version: Author: willichan Requires: Graphviz (http://graphviz.org/) #ce ---------------------------------------------------------------------------- Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declare Opt("TrayAutoPause", 0) ;0=no pause, 1=Pause Opt("TrayMenuMode", 0) ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID not return Opt("TrayIconHide", 0) ;0=show, 1=hide tray icon Global Const $MyName=StringLeft(@ScriptName, StringInStr(@ScriptName,".", 0, -1)-1) ;get just the name portion of the script/exe name Global Const $MyMutex=$MyName & "-82243BEBC30533A3" ;name the mutex for this app Global $SQLloaded = False Global $sDbName = @ScriptDir & "\db2gv.db" ConsoleWrite($sDbName & @crlf) If _MutexExists($MyMutex) Then Exit #include <SQLite.au3> #include <SQLite.dll.au3> #include <file.au3> #include <array.au3> #include <excel.au3> _ConfigInitialize() _Main() Func _ConfigInitialize() OnAutoItExitRegister("_ConfigDestroy") ;initializers here Global $sSQliteDll = _SQLite_Startup() If @error Then MsgBox(0, "SQLite Error", "could not load the DLL") Global $sSQLiteDB = _SQLite_Open($sDbName) If $sSQLiteDB = 0 Then MsgBox(0, "SQLite Error", "could not open the database") $SQLloaded =True __CreateTables() EndFunc ;==>_ConfigInitialize Func _ConfigDestroy() ;destructors here If $SQLloaded Then _SQLite_Close() _SQLite_Shutdown() EndIf EndFunc ;==>_ConfigDestroy Func _MutexExists($sOccurenceName) Local $ERROR_ALREADY_EXISTS = 183, $handle, $lastError $sOccurenceName = StringReplace($sOccurenceName, "\", "") $handle = DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $sOccurenceName) $lastError = DllCall("kernel32.dll", "int", "GetLastError") Return $lastError[0] = $ERROR_ALREADY_EXISTS EndFunc ;==>_MutexExists Func __CreateTables() _SQLite_Exec($sSQLiteDB, "DROP TABLE IF EXISTS nodes;") _SQLite_Exec($sSQLiteDB, "CREATE TABLE IF NOT EXISTS nodes( name TEXT PRIMARY KEY, fileexists INTEGER);") _SQLite_Exec($sSQLiteDB, "DROP TABLE IF EXISTS links;") _SQLite_Exec($sSQLiteDB, "CREATE TABLE IF NOT EXISTS links( id INTEGER PRIMARY KEY, name1 TEXT, name2 TEXT, weight INTEGER);") EndFunc Func _Main() Local $sInfile, $vResult, $iErrLoop $sInfile = FileOpenDialog("Source File", @WorkingDir, "Excel files (*.xl*)", 1 + 2) If Not FileExists($sInfile) Then MsgBox(0, "Excel Links Mapper Error", "Unable to locate source file") Exit EndIf $vResult = $SQLITE_IOERR $iErrLoop = 5 While $vResult = $SQLITE_IOERR $vResult = _SQLite_Exec($sSQLiteDB, "INSERT OR IGNORE INTO nodes ('name', 'fileexists') VALUES (" & _SQLite_FastEscape($sInfile) & ", 1);") If Not $vResult = $SQLITE_OK Then Sleep(100) $iErrLoop -= 1 If $iErrLoop = 0 Then ConsoleWrite($iErrLoop & " tries" & @CRLF & $sInfile & @CRLF) $vResult = $SQLITE_OK EndIf WEnd _GetExcelLinks($sInfile) Global $hOutfile = FileOpen(@ScriptDir & "\" & $MyName & ".gv", 2) If $hOutfile = -1 Then MsgBox(0, $MyName & " ERROR", "Unable to upen file for output") Exit EndIf _WriteHeader() _WriteNodes() _WriteLinks() _WriteFooter() FileClose($hOutfile) _GenerateGraph() ShellExecute(@ScriptDir & '\ExcelLinksMapper.png') EndFunc ;==>_Main Func _GetExcelLinks($strFileName) Local $hQuery, $aCount, $iErrLoop, $vResult ConsoleWrite($strFileName & @CRLF) Local $iLoop, $iExists Local $aLinks Local Const $xlExcelLinks = 1 Local $oExcel = _Excel_Open() Local $ret = _Excel_BookOpen_NoUpdate($oExcel, $strFileName, True, True) Local $err = @error If $err Then If Not IsObj($oExcel) Then ConsoleWrite($ret & " - " & $err & @CRLF) Exit EndIf EndIf $aLinks = $oExcel.ActiveWorkbook.LinkSources($xlExcelLinks) _Excel_BookClose($oExcel, False) _Excel_Close($oExcel, False, True) If IsArray($aLinks) Then If UBound($aLinks) > 0 Then For $iLoop = 0 To UBound($aLinks) - 1 If $aLinks[$iLoop] <> $strFileName Then $iExists = FileExists($aLinks[$iLoop]) ConsoleWrite("DEBUG - Calling WriteNode()") __WriteNode($aLinks[$iLoop], $iExists) ConsoleWrite("DEBUG - Calling WriteLink()") __WriteLink($strFileName, $aLinks[$iLoop]) If $iExists And ($aLinks[$iLoop] <> $strFileName) Then _GetExcelLinks($aLinks[$iLoop]) EndIf Next EndIf EndIf EndFunc ;==>_GetExcelLinks Func __WriteNode($sName, $iExists) Local $iErrLoop = 5 ;Number of attempts to make Local $vResult Do ConsoleWrite("DEBUG - WriteNode()" & @CRLF & " _SQLite_Exec(INSERT OR IGNORE INTO nodes ('name', 'fileexists') VALUES (" & _SQLite_FastEscape($sName) & ", " & $iExists & ");) - create node entry" & @CRLF) $vResult = _SQLite_Exec($sSQLiteDB, "INSERT OR IGNORE INTO nodes ('name', 'fileexists') VALUES (" & _SQLite_FastEscape($sName) & ", " & $iExists & ");") If Not $vResult = $SQLITE_OK Then Sleep(100) $iErrLoop -= 1 If $iErrLoop = 0 Then $vResult = $SQLITE_OK ;Used up all our attempts, so simulate a success Until $vResult = $SQLITE_OK EndFunc ;==>__WriteNode Func __WriteLink($sName1, $sName2) Local $iErrLoop = 5 ;Number of attempts to make Local $vResult, $hQuery, $vCount ConsoleWrite("DEBUG - WriteNode()" & @CRLF & " _SQLite_Query(SELECT weight FROM links WHERE 'name1'=" & _SQLite_FastEscape($sName1) & " AND 'name2'=" & _SQLite_FastEscape($sName2) & ";) - lookup link entry" & @CRLF) _SQLite_Query($sSQLiteDB, "SELECT weight FROM links WHERE 'name1'=" & _SQLite_FastEscape($sName1) & " AND 'name2'=" & _SQLite_FastEscape($sName2) & ";", $hQuery) ConsoleWrite("DEBUG - _SQLite_FetchData()" & @CRLF) _SQLite_FetchData($hQuery, $vCount) If UBound($vCount) > 1 Then _ArrayDisplay($vCount) If $SQLITE_OK And UBound($vCount) > 1 Then $vCount = $vCount[1] + 1 Else $vCount = 1 EndIf Do If $vCount = 1 Then ConsoleWrite("DEBUG - _SQLite_Exec() - create link entry" & @CRLF) $vResult = _SQLite_Exec($sSQLiteDB, "INSERT INTO links ('name1', 'name2', 'weight') VALUES (" & _SQLite_FastEscape($sName1) & ", " & _SQLite_FastEscape($sName2) & ", " & $vCount & ");") Else ConsoleWrite("DEBUG - _SQLite_Exec() - update link entry" & @CRLF) $vResult = _SQLite_Exec($sSQLiteDB, "UPDATE links SET 'weight'=" & $vCount & " WHERE 'name1'=" & _SQLite_FastEscape($sName1) & " AND 'name2=" & _SQLite_FastEscape($sName2) & ";") EndIf If Not $vResult = $SQLITE_OK Then Sleep(100) $iErrLoop -= 1 If $iErrLoop = 0 Then $vResult = $SQLITE_OK ;Used up all our attempts, so simulate a success Until $vResult = $SQLITE_OK EndFunc ;==>__WriteLink ; #FUNCTION# ==================================================================================================================== ; Author ........: SEO <locodarwin at yahoo dot com> ; Modified.......: litlmike, water, GMK, willichan ; =============================================================================================================================== Func _Excel_BookOpen_NoUpdate($oExcel, $sFilePath, $bReadOnly = Default, $bVisible = Default, $sPassword = Default, $sWritePassword = Default) If Not IsObj($oExcel) Or ObjName($oExcel, 1) <> "_Application" Then Return SetError(1, @error, 0) If Not FileExists($sFilePath) Then Return SetError(2, 0, 0) If $bReadOnly = Default Then $bReadOnly = False If $bVisible = Default Then $bVisible = True ;; changing the second parameter on the following line to a 0 tells Excel not to update any links. Local $oWorkbook = $oExcel.Workbooks.Open($sFilePath, 0, $bReadOnly, Default, $sPassword, $sWritePassword) If @error Then Return SetError(3, @error, 0) $oExcel.Windows($oWorkbook.Name).Visible = $bVisible ; If a read-write workbook was opened read-only then return an error If $bReadOnly = False And $oWorkbook.Readonly = True Then Return SetError(4, 0, $oWorkbook) Return $oWorkbook EndFunc ;==>_Excel_BookOpen_NoUpdate Func _GenerateGraph() RunWait(@ScriptDir & '\GraphViz238\bin\dot.exe -Tpng "' & @ScriptDir & '\' & $MyName & '.gv" -o "' & @ScriptDir & '\ExcelLinksMapper.png"') EndFunc ;==>_GenerateGraph Func _WriteHeader() __OutLine(0, "digraph main {") EndFunc ;==>_WriteHeader Func _WriteNodes() Local $aResult, $iRows, $iColumns, $iRval Local $iLoop, $sStyle __OutLine(1, "// Nodes") $iRval = _SQLite_GetTable($sSQLiteDB, "SELECT name, fileexists FROM nodes;", $aResult, $iRows, $iColumns) If @error Then ConsoleWrite("_WriteNodes()" & @CRLF & "_SQLite_GetTable") If $iRval = $SQLITE_OK Then For $iLoop = 1 To $iRows If $aResult[($iLoop * 2) + 2] > 0 Then $sStyle = "normal" Else $sStyle = "missing" EndIf __OutNode($aResult[1 + (2 * $iLoop)], $sStyle) ;; Next Else MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg() & @CRLF & "in _WriteNotes() calling _SQLite_GetTable()") Exit EndIf EndFunc ;==>_WriteNodes Func __OutNode($sName, $sStyle = Default) If $sStyle = Default Then $sStyle = "Normal" Switch StringLower($sStyle) Case "missing" __OutLine(1, __MakeName($sName) & ' [label="' & StringReplace($sName, "\", "\\") & '",color=red,fontcolor=red,shape=octagon];') Case Else ;"normal", Default __OutLine(1, __MakeName($sName) & ' [label="' & StringReplace($sName, "\", "\\") & '",color=black,fontcolor=black,shape=box];') EndSwitch EndFunc ;==>__OutNode Func _WriteLinks() Local $aResult, $iRows, $iColumns, $iRval Local $iLoop, $sStyle, $aCount __OutLine(1, "// Links") $iRval = _SQLite_GetTable($sSQLiteDB, "SELECT name1, name2 FROM links ORDER BY name1 ASC, name2 ASC;", $aResult, $iRows, $iColumns) If $iRval = $SQLITE_OK Then For $iLoop = 1 To $iRows __OutLink($aResult[1 + (2 * $iLoop)], $aResult[2 + (2 * $iLoop)]) Next Else MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg()) Exit EndIf EndFunc ;==>_WriteLinks Func __OutLink($sName1, $sName2, $iWeight = 1) __OutLine(1, __MakeName($sName1) & ' -> ' & __MakeName($sName2) & ';') EndFunc ;==>__OutLink Func _WriteFooter() __OutLine(0, "}") EndFunc ;==>_WriteFooter Func __OutLine($iTabs, $sText) Local $iLoop If $iTabs > 0 Then For $iLoop = 1 To $iTabs FileWrite($hOutfile, " ") ;ConsoleWrite(" ") Next EndIf FileWriteLine($hOutfile, $sText) EndFunc ;==>__OutLine Func __MakeName($sText) Local $sNewName = StringReplace($sText, "\", " ") $sNewName = StringReplace($sNewName, "/", " ") $sNewName = StringReplace($sNewName, "'", " ") $sNewName = StringReplace($sNewName, '"', " ") $sNewName = StringReplace($sNewName, ':', " ") $sNewName = StringReplace($sNewName, '.', " ") $sNewName = StringReplace($sNewName, '-', " ") $sNewName = StringReplace($sNewName, '$', " ") $sNewName = StringStripWS($sNewName, 8) Return StringLower($sNewName) EndFunc ;==>__MakeName  
    • Dimmae
      By Dimmae
      Hello,
      at first: i'm new here, so please forgive me my mistakes, and show them to me, just that i can learn to do better in the future.
      Now to my Problem: i have an excel sheet, where i just need some columns for further actions, but i have no idea how to add single columns to a new array.
      I found the following code(the one i just added as a file) from 'water' in this forum, but i wont get how i could add multiple columns into a new array.
      The biggest problem in my situation is that i dont know the count of the rows i need for the array, i just got a fix number of rows, which is 4.
       
      Hope you can help me, and sry again for this 'unlucky illustration'.
       
      btw: how can i add code shown as code here, instead of posting it as a attached file?.
       
       
       
      autoit-select-column.au3
      defects.xlsx
    • LoneWolf_2106
      By LoneWolf_2106
      Hi,
      i have an error:
      ==> The requested action with this object has failed.: $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count $iRowCount = .Range(^ ERROR  
      My code is:
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) Sleep(1000) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count Sleep(1000) _Excel_RangeWrite($oWorkbook_1, $oWorkbook_1.ActiveSheet,$aFileList[$i][2] , "AB3:AB"&$iRowCount) I have added some sleep because the application was crashing more often before, so i thought to slow down the code execution.
      But i didn't solve the issue.
      Has anyone an idea of what the problem might be?
      Thanks in advance.