Sign in to follow this  
Followers 0
Tarakos

So simple, but impossible for me! ActiveCell in excel with Autoit

6 posts in this topic

Hello to everybody,
 
what I want to know is which row and which column is the active cell in the file excel.
I think it's really simple, but I've tried my best and I didn't succeed.
I haven't find anything in internet. Help me, please!  :sweating:
 
I use the file "test.xls" to write many records, but I want to know WHERE I'm writing the records BEFORE the records are written and before writing anything in the sheet.
The ActiveCell may be everywhere in the sheet.
 
 
#Include <Excel.au3>
$oExcel = _ExcelBookAttach("C:test.xls")
 
$TheRow = $oExcel.ActiveCell.Row
 
The error is:
$TheRow = $oExcel.ActiveCell.Row
$TheRow = $oExcel.ActiveCell^ ERROR
 
Error: The requested action with this object has failed
 
Someone would correct my code, please?

Share this post


Link to post
Share on other sites



Try this:

#include <Excel.au3>

$oExcel = _ExcelBookOpen(@DesktopDir & "\ActiveCellTest.xls")
$sCell = $oExcel.ActiveCell.Address
    MsgBox(0, "", $sCell)

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

BTW: When posting code please add tags as described >here.


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

 

Try this:

#include <Excel.au3>

$oExcel = _ExcelBookOpen(@DesktopDir & "\ActiveCellTest.xls")
$sCell = $oExcel.ActiveCell.Address
    MsgBox(0, "", $sCell)

 

Thanks for your suggest.

The error is in  "_ExcelBookAttach" ;

with _ExcelBookOpen, it works. I don't understand, but it works!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

But if I have the file excel opened (that is my case), there is another way to solve the problem?

I've tried to adapt my code with _ExcelBookOpen, but it solves the "ActiveCell" problem, but it gives me other problems with my code.

I would like to study in deep the reason why ActiveCell doesn't work with an object like _ExcelBookAttach("C:test.xls").

There are different "objects" ???

I'd rather to leave _ExcelBookAttach("C:test.xls") in my code, so the question of my topic is still unanswered.

Thank you to all other suggests.

Edited by Tarakos

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ok, I think to have solved it. This is what I found:

; #FUNCTION# ====================================================================================================================
; Name...........: _ExcelBookOpen
; Description ...: Opens an existing workbook and returns its object identifier.


; #FUNCTION# ====================================================================================================================
; Name...........: _ExcelBookAttach
; Description ...: Attach to the first existing instance of Microsoft Excel where the search string matches based on the selected mode.
; Return values .: Success   - Returns an object variable pointing to the Excel.Application, workbook object

So my code becomes:

#Include <Excel.au3>
$oExcel = _ExcelBookAttach("C:\test.xls")


$sCell = $oExcel.Application.ActiveCell.Row

It was really simple...... :thumbsup: and now possible!!

Thanks to JLogan for the idea!!! Bye,

Edited by Tarakos

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  
Followers 0