Valnurat

_Excel_RangeFind

23 posts in this topic

I'm trying to find a text in my excel with Excel_RangeFind, but I get an error.

My code:

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

; Create a constant variable in Local scope of the message to display in FileOpenDialog.
Local Const $sMessage = "Select a single file of any type."
; Display an open dialog to select a file.
Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST)
If @error Then
    ; Display the error message.
    MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")
    ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
    FileChangeDir(@ScriptDir)
    Exit
Else
    ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
    FileChangeDir(@ScriptDir)
    ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog.
    $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
    ; Create application object and open an example workbook
    Local $oExcel = _Excel_Open()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $sFileOpenDialog)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error opening workbook '" & @ScriptDir & "\Extras\_Excel1.xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oExcel)
        Exit
    EndIf

    ; *****************************************************************************
    ; Find all occurrences of string "=C10*10" in the formulas, exact match
    ; *****************************************************************************
    Local $aResult = _Excel_RangeFind($oWorkbook, "Maskprov 7", Default, Default, $xlWhole)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example 2", "Error searching the range." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example 2", "Find all occurrences of string 'Maskprov 7' in the formulas, exact match." & @CRLF & "Data successfully searched.")
    _ArrayDisplay($aResult, "")
EndIf

My error:

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
"C:\Program Files (x86)\AutoIt3\Include\Excel.au3" (656) : ==> The requested action with this object has failed.:
$aResult[$iIndex][1] = $oMatch.Name.Name
$aResult[$iIndex][1] = $oMatch^ ERROR
->21:10:04 AutoIt3.exe ended.rc:1
+>21:10:04 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 11.22

Do I something wrong?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites



This subject has been discussed a few times. It is a bug in Autoit 3.3.14.2.
Either downgrade to AutoIt 3.3.12.0 or modify _Excel_RangeFind as described in one of the threads I mentioned.


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

I saw in another post that I should do this and run it, but it does not help.

;$aResult[$iIndex][1] = $oMatch.Name.Name

My version of Autoit is 3.6.2


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

There is no 3.6.2 version of AutoIt.
What does

ConsoleWrite(@AutoItVersion & @CRLF)

return?


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

Maybe it was my Scite version. :)


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Oh, I just saw that my excel.au3 is a readonly file.

I did made it not readonly, but how can I save it as excel.au3?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

I manage to save it on another location, but now I get this error:

"C:\Users\DKSOKVK\Documents\AutoIT\IncludeMyUDF\Excel.au3" (660) : ==> The requested action with this object has failed.:
$aResult[$iIndex][5] = $oMatch.Comment.Text
$aResult[$iIndex][5] = $oMatch.Comment^ ERROR
->22:40:49 AutoIt3.exe ended.rc:1
+>22:40:49 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 10.07

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
1 hour ago, Valnurat said:

I manage to save it on another location, but now I get this error:

"C:\Users\DKSOKVK\Documents\AutoIT\IncludeMyUDF\Excel.au3" (660) : ==> The requested action with this object has failed.:
$aResult[$iIndex][5] = $oMatch.Comment.Text
$aResult[$iIndex][5] = $oMatch.Comment^ ERROR
->22:40:49 AutoIt3.exe ended.rc:1
+>22:40:49 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 10.07

 

Try to use this RangeFind modified function by @MichaelHB:
 

Func __Excel_RangeFind($oWorkbook, $sSearch, $vRange = Default, $iLookIn = Default, $iLookAt = Default, $bMatchcase = Default)
    If Not IsObj($oWorkbook) Or ObjName($oWorkbook, 1) <> "_Workbook" Then Return SetError(1, 0, 0)
    If StringStripWS($sSearch, 3) = "" Then Return SetError(2, 0, 0)
    If $iLookIn = Default Then $iLookIn = $xlValues
    If $iLookAt = Default Then $iLookAt = $xlPart
    If $bMatchcase = Default Then $bMatchcase = False
    Local $oMatch, $sFirst = "", $bSearchWorkbook = False, $oSheet
    If $vRange = Default Then
        $bSearchWorkbook = True
        $oSheet = $oWorkbook.Sheets(1)
        $vRange = $oSheet.UsedRange
    ElseIf IsString($vRange) Then
        $vRange = $oWorkbook.Activesheet.Range($vRange)
        If @error Then Return SetError(3, @error, 0)
    EndIf
    Local $aResult[100][4], $iIndex = 0, $iIndexSheets = 1, $iNumberOfSheets = $oWorkbook.Worksheets.Count
    While 1
        $oMatch = $vRange.Find($sSearch, Default, $iLookIn, $iLookAt, Default, Default, $bMatchcase)
        If @error Then Return SetError(4, @error, 0)
        If IsObj($oMatch) Then
            $sFirst = $oMatch.Address
            While 1
                $aResult[$iIndex][0] = $oMatch.Worksheet.Name
                $aResult[$iIndex][1] = $oMatch.Address
                $aResult[$iIndex][2] = $oMatch.Value
                $aResult[$iIndex][3] = $oMatch.Formula
                $iIndex = $iIndex + 1
                If Mod($iIndex, 100) = 0 Then ReDim $aResult[UBound($aResult, 1) + 100][4]
                $oMatch = $vRange.Findnext($oMatch)
                If Not IsObj($oMatch) Or $sFirst = $oMatch.Address Then ExitLoop
            WEnd
        EndIf
        If Not $bSearchWorkbook Then ExitLoop
        $iIndexSheets = $iIndexSheets + 1
        If $iIndexSheets > $iNumberOfSheets Then ExitLoop
        $sFirst = ""
        $oSheet = $oWorkbook.Sheets($iIndexSheets)
        If @error Then ExitLoop
        $vRange = $oSheet.UsedRange
    WEnd
    ReDim $aResult[$iIndex][4]
    Return $aResult
EndFunc

You could find more info about this here:
https://www.autoitscript.com/forum/topic/182057-how-do-i-select-a-worksheet-in-excel

Regards
Alien.

Share this post


Link to post
Share on other sites
1 hour ago, water said:

This subject has been discussed a few times. It is a bug in Autoit 3.3.14.2.
Either downgrade to AutoIt 3.3.12.0 or modify _Excel_RangeFind as described in one of the threads I mentioned.

If I downgrade do I miss other stuff?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#10 ·  Posted

1 hour ago, Valnurat said:

If I downgrade do I miss other stuff?

My advise: try the Modified version of RangeFind if you can't make it work in the way you need, then Downgrade...

Regards
Alien.

Share this post


Link to post
Share on other sites

#11 ·  Posted

Check History / ChangeLog in the help file and you will see what you will be missing.


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

#12 ·  Posted

Hmm, I have uninstalled AutoIT v. 3.3.14.2 and I uninstall SciTE v. 3.6.2.

I installed AutoIT v. 3.2.12.0, but when I trying to install SciTE4AutoIT3 16.306.1237.0 I get an error (SciTE.JPG). I have just pressed "ok".

When I'm trying to compile I get an error (SciTE1.jpg)

What do I need to do?

SciTE.JPG

SciTE1.JPG


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#13 ·  Posted

I reinstall AutoIT to 3.3.14.2 and SciTE to 3.6.2 and modified the RangeFind.

Save the original Excel.au3 to ExcelModify.au3 and placed it in my own folder for non-original include au3.

When I complie it I get this error:

>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\DKSOKVK\Documents\RAD Studio\Projects\Alfalaval\Test Apps\Consultant.au3
"C:\Users\DKSOKVK\Documents\RAD Studio\Projects\Alfalaval\Test Apps\Consultant.au3"(33,91) : error: _Excel_RangeFind(): undefined function.
 Local $aResult = _Excel_RangeFind($oWorkbook, "Maskprov 7", "B8:B1739", Default, $xlWhole)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I'm lost. Don't know what happens.

Can someone help me?

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#14 ·  Posted

You are sure ExcelModify.au3 contains function _Excel_RangeFind? How does the line

Func _Excel_RangeFind($oWorkbook, $sSearch, $vRange = Default, $iLookIn = Default, $iLookAt = Default, $bMatchcase = Default)

look like in your modified UDF? Can you please post?


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

#15 ·  Posted (edited)

Maybe I have missunderstod your recommendation, but should I not modify the original excel.au3 UDF file?

Func __Excel_RangeFind($oWorkbook, $sSearch, $vRange = Default, $iLookIn = Default, $iLookAt = Default, $bMatchcase = Default)

I saw there was 2 underscores before calling the function. After I change that it worked.

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#16 ·  Posted

You should and you did.
But you call _Excel_RangeFind (note that the function name starts with a single underscore) and in your UDF you have __Excel_RangeFind (note that the function name starts with TWO underscores).


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

#17 ·  Posted

Yes, I saw that. :>


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#18 ·  Posted

My goal is to have some info I got in a comma CVS file merged with a excel doc.

In the excel.doc the search column is B and I need to do it from row 8, because 1-7 is locked.

Do I do it correct?

I really hope someone can help me.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

#19 ·  Posted

You read the CSV into an array and then loop through this array. Search in column "B" for the key and then add the remaining data from the array?
Should be possible.
As the RangeFind problem seems to be fixed which problems do you see now?


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

#20 ·  Posted

This is my result:

Row|Sheet|Name|Cell|Value
[0]|Consultant OU - Questions - EME|$B$1573|Maskprov 7|Maskprov 7

But how do I use this info to add text into the excel doc?


Yours sincerely

Kenneth.

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

    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • nassausky
      By nassausky
      Hey all,
      Has anyone created any queries for youtube? I was thinking it might be something like this but can't quite figure it out:
      $oIE = _IECreateEmbedded() _IENavigate($oIE,"https://www.youtube.com") Local $oForms = _IETagNameGetCollection($oIE, "form") Local $sTxt = "" For $oForm In $oForms If $oForm.id = "masthead-search" Then $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id = "masthead-search-term" Then _IEFormElementSetValue($oInput, "cards") _IEFormSubmit($oForm) EndIf Next EndIf Next  
    • Skysnake
      By Skysnake
      Scite comes up occasional, almost incidentally, in some support topics.  I have not found a "Scite" topic in the forums, so this is where I will start.  I have recently been using Scite intensively, specifically with a large project and I have certain issues.  I know that Scite is not an AutoIt product, but it is so closely integrated to the core release that it makes sense to raise issues and request support here.  If this is not the right please refer me to the right forum.
      Thx
       
      Skysnake