Jump to content

Problem with Excel Read


gahhon
 Share

Recommended Posts

Hi Guys,

I was trying to read some data from the excel file and without opening the file. But I tried a lot of methods, it still open the file.

And also, I am able to capture the ColumnA value but not Column B.

Thanks for advance information.

Global $oDataA, $oDataB

Call ("ExcelRead", "B2", "C2")

Func ExcelRead($oColumnA, $oColumnB)
    Local $oPath = @ScriptDir & "\MyFile.xlsx"
    Local $oExcel = _Excel_Open()
    Local $oWorkbook = _Excel_BookOpen($oExcel, $oPath, 1, 0)

    $oDataA = _Excel_RangeRead($oWorkbook, "Sheet 1", $oColumnA)
    $oDataB = _Excel_RangeRead($oWorkbook, "Sheet 1", $oColumnB)
    MsgBox(0, "Test Value", $oDataA & ", " & $oDataB)
EndFunc

 

Edited by gahhon
Link to comment
Share on other sites

How about:

Local $oWorkbook = _Excel_BookOpen($oExcel, $oPath, True, False)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

So the Excel application AND the workbook is visible?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Then try:

Local $oExcel = _Excel_Open(False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $oPath, True)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Just now, gahhon said:

The Excel application is showed, but is empty. There's no workbook.

So it WAD ;)
To make the application invisible you have to specify this when calling _Excel_Open.
To make the workbook invisible you have to specify this when calling _Excel_BookOpen. Not needed when the whole application is invisible.

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Assume you also meant Sheet1 not "Sheet 1", you should also add _Excel_BookClose, _Excel_Close as well for example:

#include <Excel.au3>
Global $oDataA, $oDataB

ExcelRead("B2", "C2")

Func ExcelRead($oColumnA, $oColumnB)
    Local $sPath = @ScriptDir & "\MyFile.xlsx"
    Local $oExcel = _Excel_Open(False, False, False, False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $sPath, True, False)
    $sUsername = _Excel_RangeRead($oWorkbook, Default, $oColumnA)
    $sPassword = _Excel_RangeRead($oWorkbook, Default, $oColumnB)
    _Excel_BookClose($oWorkbook, False)
    _Excel_Close($oExcel)
    MsgBox(0, "Test Value", $sUsername & ", " & $sPassword)
EndFunc

 

Link to comment
Share on other sites

6 minutes ago, Subz said:

Assume you also meant Sheet1 not "Sheet 1", you should also add _Excel_BookClose, _Excel_Close as well for example:

#include <Excel.au3>
Global $oDataA, $oDataB

ExcelRead("B2", "C2")

Func ExcelRead($oColumnA, $oColumnB)
    Local $sPath = @ScriptDir & "\MyFile.xlsx"
    Local $oExcel = _Excel_Open(False, False, False, False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $sPath, True, False)
    $sUsername = _Excel_RangeRead($oWorkbook, Default, $oColumnA)
    $sPassword = _Excel_RangeRead($oWorkbook, Default, $oColumnB)
    _Excel_BookClose($oWorkbook, False)
    _Excel_Close($oExcel)
    MsgBox(0, "Test Value", $sUsername & ", " & $sPassword)
EndFunc

 

 

9 minutes ago, water said:

Then try:

Local $oExcel = _Excel_Open(False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $oPath, True)

 

Both of the solution is work fine to me. But with Subz solution, I am able to capture the ColumnB value and I dont know why. :o

And also, I did use a button trigger this function, but every 2nd time it showed the Excel Activation Error and showed 0, 0. Any idea?

Link to comment
Share on other sites

What do you mean by:

10 minutes ago, gahhon said:

Excel Activation Error

Can you please post the error message or a screen shot?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Is this an activated version of Excel you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

3 minutes ago, water said:

Is this an activated version of Excel you run?

Haha. No.

But I thought I open file, read and store, then close. It shouldn't be showing any error like that.

And also, When I got value from the MsgBox other than 0. It no showing any activation error.

Link to comment
Share on other sites

6 minutes ago, gahhon said:

Haha. No.

Unfortunately the Excel UDF can't help here. Active Excel and the problem will disappear ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The Excel UDF calls Excel functions using COM. How Excel reacts to an unregistered version can't be handled by the UDF.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

56 minutes ago, water said:

The Excel UDF calls Excel functions using COM. How Excel reacts to an unregistered version can't be handled by the UDF.

Understood. In the meantime, then I will import the TextFile method instead. Thanks for help :D

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

×
×
  • Create New...