Tarakos Posted July 9, 2013 Share Posted July 9, 2013 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! 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? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 9, 2013 Moderators Share Posted July 9, 2013 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! Link to comment Share on other sites More sharing options...
water Posted July 9, 2013 Share Posted July 9, 2013 BTW: When posting code please add tags as described >here. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
Tarakos Posted July 9, 2013 Author Share Posted July 9, 2013 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! Link to comment Share on other sites More sharing options...
Tarakos Posted July 9, 2013 Author Share Posted July 9, 2013 (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 July 9, 2013 by Tarakos Link to comment Share on other sites More sharing options...
Solution Tarakos Posted July 9, 2013 Author Solution Share Posted July 9, 2013 (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...... and now possible!! Thanks to JLogan for the idea!!! Bye, Edited July 9, 2013 by Tarakos BlackLumiere 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now