Jump to content
Sign in to follow this  
rilian

Problem with _ExcelBookAttach

Recommended Posts

rilian

I'm running AutoITv3 installed a week or two ago on a win7 64 bit platform. 

I was learning how to use the Excel.au3 UDF code. Creating a new excel doc and doing things to it works flawlessly but using _ExcelBookAttach may have a bug. 

I wanted to attach to an open excel file so I read the requisite help files. I got my code to attach to the workbook name I wanted in theory but I wasn't seeing anything showing up in the cells. Running my same code snippet using a new workbook instead of my existing, open excel workbook, my code ran fine. On a whim, I brought up the other excel file I had opened and the places I was writing data to w/ my autoit code were overwritten in this workbook instead of the one I targeted. 

Below is my code:

#include <Excel.au3>

Local $oExcel = _ExcelBookAttach("Microsoft Excel - samplenames_db.xlsx", "Title")

For $i=2 to 41
   $value=Random(100000,399999,1)
   _ExcelWriteCell($oExcel,$value,$i,3)
next

If my targeted workbook is the first workbook open, then I open another workbook, my code works on the targeted workbook flawlessly. 

I was able to repeat this behavior. Is this a bug somewhere in the _ExcelBookAttach code or am I doing something incorrectly? I would prefer not to have to close all my open workbooks to run a script targeted at an opened one. 

I should add that I got the string for the workbook title from the autoit info tool. Interesting that when I have that file open in Excel, the title reads "samplename_db.xlsx - Microsoft Excel" which is backwards from what you see in the code that was read by the info tool. Trying it the way it is displayed results in an error from the _ExcelBookAttach line. 

Thank you in advance for help with this. 

Share this post


Link to post
Share on other sites
water

The Excel UDF that comes with AutoIt only works with the active workbook and the active worksheet.

My rewrite of the Excel UDF works with as many workbooks and worksheets as you like. And it is much faster.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×