Jump to content
Sign in to follow this  

Problem with _ExcelBookAttach

Recommended Posts


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

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

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:


Active Directory (NEW 2018-12-03 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

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