Jump to content

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


Go to solution Solved by Tarakos,

Recommended Posts

Posted
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?
  • Moderators
Posted

Try this:

#include <Excel.au3>

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

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

Posted

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

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 7/9/2013 at 1:55 PM, JLogan3o13 said:

 

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!

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
  • Solution
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

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
  • Recently Browsing   0 members

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