Jump to content

Need help for Hotkey/Excel Read


Recommended Posts

Good day,

in this script I used 3 Hotkeys, How do I read A1, A2 and A3 using single hotkey?

like if I press F1 it will read _iReadA1, if I Press F1  again it will read _iReadA2, if I Press F1 again it will read _iReadA3 and if I Press F1 again it will read the first function, _iReadA1 again and so on.. need help dont know which command to use.

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

HotKeySet("{F1}", "_iReadA1")
HotKeySet("{F2}", "_iReadA2")
HotKeySet("{F3}", "_iReadA3")

While 1

    Sleep(10)

WEnd 1




Func _iReadA1()

    Local $sText = WinGetTitle("[CLASS:XLMAIN]")
    $iText = StringLeft($sText, 16)
    Local $sWorkbook = $iText & ".xlsx"
    $oWorkbook = _Excel_BookAttach($sWorkbook, "filename")
    Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A1")
    MsgBox(0, "", $sResult)

EndFunc   ;==>_iReadA1

Func _iReadA2()

    Local $sText = WinGetTitle("[CLASS:XLMAIN]")
    $iText = StringLeft($sText, 16)
    Local $sWorkbook = $iText & ".xlsx"
    $oWorkbook = _Excel_BookAttach($sWorkbook, "filename")
    Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A2")
    MsgBox(0, "", $sResult)

EndFunc   ;==>_iReadA2

Func _iReadA3()

    Local $sText = WinGetTitle("[CLASS:XLMAIN]")
    $iText = StringLeft($sText, 16)
    Local $sWorkbook = $iText & ".xlsx"
    $oWorkbook = _Excel_BookAttach($sWorkbook, "filename")
    Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A3")
    MsgBox(0, "", $sResult)

EndFunc   ;==>_iReadA3

 

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

  • Moderators

Didn't invest a lot of time reading the help file examples, did you? If you read a single cell it is returned as a string, if you read a number of cells, it is returned as an array. Try this:

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

HotKeySet("{F1}", "_iReadAll")

While 1
    Sleep(10)
WEnd

Func _iReadAll()

    Local $sText = WinGetTitle("[CLASS:XLMAIN]")
    $iText = StringLeft($sText, 16)
    Local $sWorkbook = $iText & ".xlsx"
    $oWorkbook = _Excel_BookAttach($sWorkbook, "filename")
    Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A1:A3")
    _ArrayDisplay($sResult)

EndFunc   ;==>_iReadAll

BTW, on my machine $iText returns just "Microsoft Excel", so unless your workbook is named "Microsoft Excel.xlsx", you're not going to successfully attach.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Good day @JLogan3o13 thanks for the reply, i tried your script and it works fine, but what I want to achieved is read the cell one by one using a single hotkey, its like a loop, If I press F1 it will read first function, then if I press F1 again it will jump to 2nd function, then if I press F1 again it will jump to 3rd function, and if I press F1 again it will jump to 1st function,  is this possible??? im stuck, please help... :'(:'(

 

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

HotKeySet("{F1}", "_iReadA1")
HotKeySet("{F2}", "_iReadA2")
HotKeySet("{F3}", "_iReadA3")

While 1

    Sleep(10)

WEnd 1




Func _iReadA1();1st function

    Local $sText = WinGetTitle("[CLASS:XLMAIN]")
    $iText = StringLeft($sText, 16)
    Local $sWorkbook = $iText & ".xlsx"
    $oWorkbook = _Excel_BookAttach($sWorkbook, "filename")
    Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A1")
    MsgBox(0, "", $sResult)

EndFunc   ;==>_iReadA1

Func _iReadA2();2nd function

    Local $sText = WinGetTitle("[CLASS:XLMAIN]")
    $iText = StringLeft($sText, 16)
    Local $sWorkbook = $iText & ".xlsx"
    $oWorkbook = _Excel_BookAttach($sWorkbook, "filename")
    Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A2")
    MsgBox(0, "", $sResult)

EndFunc   ;==>_iReadA2

Func _iReadA3();3rd function

    Local $sText = WinGetTitle("[CLASS:XLMAIN]")
    $iText = StringLeft($sText, 16)
    Local $sWorkbook = $iText & ".xlsx"
    $oWorkbook = _Excel_BookAttach($sWorkbook, "filename")
    Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A3")
    MsgBox(0, "", $sResult)

EndFunc   ;==>_iReadA3
Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

Why not just make a counter and a switch statement that executes the next function you want based off the counter number?

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

hi @MikahS kind of confused with your counter, and searched the help file no command for counter,

you mean something like this or could you give me a little bit of example???

$iCount = 0
Do
    _Callsomefunc()
    $iCount += 1
Until $iCount = 6;

 

 

 

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

It's just a variable with a number that gets incremented. Here is an example:

#include <GUIConstants.au3>

HotKeySet("{F1}", "Example")

Local $counter = 0

While 1

WEnd

Func Example()
    Switch $counter
        Case 0
            MsgBox(0, "Test", "You have run the function for the first time!")
            $counter += 1
        Case 1
            extFunc1()
            $counter += 1
        Case 2
            extFunc2()
            $counter += 1
        Case 3
            extFunc3()
            $counter += 1
        Case Else
            MsgBox(0, "Test", "You've run through my examples already!")
            Exit
    EndSwitch
EndFunc

Func extFunc1()
    MsgBox(0, "Test", "We are in extFunc1!")
EndFunc

Func extFunc2()
    MsgBox(0, "Test", "We are in extFunc2!")
EndFunc

Func extFunc3()
    MsgBox(0, "Test", "We are in extFunc3!")
EndFunc

 

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

@232showtime My pleasure. :) 

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...