Jump to content
Sign in to follow this  
The-dude

Excel RangRead Help! - (Moved)

Recommended Posts

Hi there!

I'm just getting back into programming and I've hit a road block on my script. I'm trying to write a script to say "Open this workbook, if cell B2 on Sheet1 is Blank, end script. If not, continue to next step". I don't need a message box or any pop-up.

Here's what I've got so far....

Local $oExcel_1 = _Excel_Open()
Local $sWorkbook = "C:MyFiles"
Local $oWorkbook = _Excel_BookOpen($oExcel_1,$sWorkbook)
Local $_read = _Excel_RangeRead ($oWorkbook,"sheet1","B2")

Any help would be greatly appreciated!

-The Dude Abides

Share this post


Link to post
Share on other sites

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@The-dude You don't exactly specify what isn't working for you, but at a guess, you're trying to open a file named "C:MyFiles", you need to put in the full path to the workbook you want to open.

Edited by JLogan3o13

"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!

Share this post


Link to post
Share on other sites

@JLogan3o13 Sorry I thought my line of text "Open this workbook, if cell B2 on Sheet1 is Blank, end script. If not, continue to next step" was enough info.

The "C:\MyFiles" was just an example of the file location. I should have included a file name and extension as that could have been confusing, should be something like this "C:\MyFiles\MyWorkBook.csv".

 

Share this post


Link to post
Share on other sites
48 minutes ago, The-dude said:

@JLogan3o13 Sorry I thought my line of text "Open this workbook, if cell B2 on Sheet1 is Blank, end script. If not, continue to next step" was enough info.

It was not. You explain what you want to do, but not where you're stuck, what you've tried on your own, what error you're seeing, etc. (again, the link in my signature shows just what information we need from you). Your code works for me when I point it at an excel file with data in B2 on sheet1, so (guessing) if you're just looking for suggestions on the If>>Then step, you just need to do something like this:

#include <Excel.au3>

Local $oExcel_1 = _Excel_Open()
Local $sWorkbook = "C:\MyFiles.xlsx"
Local $oWorkbook = _Excel_BookOpen($oExcel_1,$sWorkbook)
Local $_read = _Excel_RangeRead($oWorkbook, "sheet1", "B2")

If $_read <> "" Then
    ConsoleWrite($_read & @CRLF)
    ;Or other steps as needed, the exit takes care of itself if B2 is empty
EndIf

_Excel_BookClose($oWorkbook)
_Excel_Close($oExcel_1)

 


"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!

Share this post


Link to post
Share on other sites

@JLogan3o thank you so much! I haven't been able to test it yet as my companies virus protection flagged autoit yet again... once it's back in action I'll give it a try! It was the "IF" script that I was getting hung up on. 

Share this post


Link to post
Share on other sites

@JLogan3o13 I tried implementing the script you provided and while the script ran successfully, it didn't actually stop the script if it found a blank cell in B2. Do you think you can take a look at my full script below and let me know what I'm doing wrong? 

#include <Excel.au3>

Local $oExcel_1 = _Excel_Open()
Local $sWorkbook = "M:\MyFiles\CSV_generator.xlsm"
Local $oWorkbook = _Excel_BookOpen($oExcel_1,$sWorkbook)

WinActivate($oWorkbook)

Sleep (2000)

Send("{SPACE}")

_Excel_Close($oExcel_1, Default,True)

Local $oExcel_1 = _Excel_Open()
Local $sWorkbook = "M:\MyFiles\sheet1.csv"
Local $oWorkbook = _Excel_BookOpen($oExcel_1,$sWorkbook)
Local $_read = _Excel_RangeRead ($oWorkbook,"sheet1","B2")

If $_read <> "" Then
    ConsoleWrite($_read & @CRLF)
    ;Or other steps as needed, the exit takes care of itself if B2 is empty
EndIf

_Excel_BookClose($oWorkbook)
_Excel_Close($oExcel_1, Default,False)

Run("mstsc.exe")
Sleep (1000)
Send("{ENTER}")
Sleep (1000)
Send ( "password")
Sleep(1000)
Send("{ENTER}")

Sleep(1000)

Run("anotherprogram.exe")

 

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...