water Posted December 26, 2018 Share Posted December 26, 2018 (edited) You need two variables. One holding the string ($s...) of the workbook name and the other ($o...) holding the workbook object as returned by _Excel_BookAttach. #include <Excel.au3> #include <MsgBoxConstants.au3> Local $sWorkBook = "1.xls" Locla $oExcel = _Excel_Open() If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error creating Excel object! @error = " & @error & ", @extended = " & @extended) Local $oWorkBook = _Excel_BookAttach($sWorkbook, "title") If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error attaching to the workbook! @error = " & @error & ", @extended = " & @extended) $oWorkBook.ActiveSheet.Shapes.Range("Oval 1").Delete If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error deleting shape! @error = " & @error & ", @extended = " & @extended) Edited December 26, 2018 by water 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...
LazyVasily Posted December 26, 2018 Author Share Posted December 26, 2018 water, I'm using your script. #include <Excel.au3> #include <MsgBoxConstants.au3> Local $sWorkBook = "1.xls" Local $oExcel = _Excel_Open() If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error creating Excel object! @error = " & @error & ", @extended = " & @extended) Local $oWorkBook = _Excel_BookAttach($sWorkbook, "title") If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error attaching to the workbook! @error = " & @error & ", @extended = " & @extended) $oWorkBook.ActiveSheet.Shapes.Range("Oval 1").Delete If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error deleting shape! @error = " & @error & ", @extended = " & @extended) The script still can't find the window "1.xls". Shows the error "Error attaching to the workbook". Link to comment Share on other sites More sharing options...
water Posted December 26, 2018 Share Posted December 26, 2018 At the moment I have no Windows sytem available for testing. So we need to play a bit. How about this: #include <Excel.au3> #include <MsgBoxConstants.au3> Local $sWorkBook = "1.xls" Local $oExcel = _Excel_Open() If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error creating Excel object! @error = " & @error & ", @extended = " & @extended) Local $oWorkBook = _Excel_BookAttach($sWorkbook, "filename") If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error attaching to the workbook! @error = " & @error & ", @extended = " & @extended) $oWorkBook.ActiveSheet.Shapes.Range("Oval 1").Delete If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error deleting shape! @error = " & @error & ", @extended = " & @extended) 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...
LazyVasily Posted December 26, 2018 Author Share Posted December 26, 2018 water, This script still can't find window "1.xls". Shows the error "Error attaching to the workbook". Why do you write about "filename" ? I asked about the "title". Link to comment Share on other sites More sharing options...
water Posted December 26, 2018 Share Posted December 26, 2018 1 hour ago, LazyVasily said: Why do you write about "filename" ? because it does not matter how we access the workbook - as long as it works Maybe tomorrow I have access to a Windows system and will then post a working example. 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...
water Posted December 27, 2018 Share Posted December 27, 2018 The example script I posted above runs without error when I manually open the "1.xls" (not XLSX) workbook which is stored in the same directory as the script. Can you please verify that this is true for you as well? I run AutoIt 3.3.14.4 with Office 2016 on a Windows 7 system. 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...
Nine Posted December 27, 2018 Share Posted December 27, 2018 2 hours ago, water said: The example script I posted above runs without error when I manually open the "1.xls" Confirming the same works perfectly for me. Can also work thru _Excel_BookList ($oExcel) ! “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JoHanatCent Posted December 27, 2018 Share Posted December 27, 2018 @Lazy Why do you write about "filename" ? This is as used in _Excel_BookAttach. Look at the help example. Tested and working as requested: #include <Excel.au3> #include <MsgBoxConstants.au3> Local $sWorkBook = "1.xls" Local $oExcel = _Excel_Open() If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error creating Excel object! @error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\1.xls") If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookAttach Example", "Error opening workbook '" & @ScriptDir & "\1.xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf Local $oWorkBook = _Excel_BookAttach($sWorkbook, "filename") If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error attaching to the workbook! @error = " & @error & ", @extended = " & @extended) $oWorkBook.ActiveSheet.Shapes.Range("Oval 1").Delete If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error deleting shape! @error = " & @error & ", @extended = " & @extended) Link to comment Share on other sites More sharing options...
LazyVasily Posted December 27, 2018 Author Share Posted December 27, 2018 JoHanatCent, Your script does not work. The script opens an additional copy of file 1.xls (read-only). In this copy - it removes the shape "Oval 1". The script then stops running. As a result - I have one open file 1.xls with two shapes, and one open file 1.xls (read-only) with one shape. No need to open file 1.xls because it's already open. You used the "filename" parameter again. I asked about using $sMode "Title". (https://www.autoitscript.com/autoit3/docs/libfunctions/_Excel_BookAttach.htm ) Link to comment Share on other sites More sharing options...
JoHanatCent Posted December 30, 2018 Share Posted December 30, 2018 * Delete the part belonging to _Excel_BookOpen. * Put the title of the Excel window in $sWorkBook = * Use _Excel_BookAttach($sWorkbook, "Title") Working just as well. Link to comment Share on other sites More sharing options...
TheSaint Posted December 30, 2018 Share Posted December 30, 2018 (edited) @LazyVasily - You should keep your variables unique. Now you have both the same, so you did not understand what water was telling you. You had your two different variables the wrong way round. Instead of - $oWorkBook = _Excel_BookAttach($sWorkbook, "title") $oWorkBook.ActiveSheet.Shapes.Range("Oval 1").Delete It should have been - $sWorkBook = _Excel_BookAttach($oWorkbook, "Title") $sWorkBook.ActiveSheet.Shapes.Range("Oval 1").Delete As you had already declared $oWorkbook as the Title variable with this line - Local $oWorkBook = "1.xls" Or you could have just changed that instead, to - Local $sWorkBook = "1.xls" Please note, that I have also made "title" as propercase "Title", as case might be important ... not sure. It is propercase (or titlecase) in the Help file anyway. Have you tried specifying the full path and using the FilePath option instead? _Excel_BookAttach Get at least one variant working and then you can help troubleshoot why the other isn't working. Never mind, I was referring to posts on Page 1. This is the second time that an additional Page has not been shown to me. Something screwy going on. I'd scrolled right down to see if you had been replied to. Now that I recollect it did seem odd that your last reply was Wednesday. Either that or I am losing my marbles. Edited December 30, 2018 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
water Posted December 30, 2018 Share Posted December 30, 2018 (edited) 14 minutes ago, TheSaint said: Please note, that I have also made "title" as propercase "Title", as case might be important ... not sure. It is propercase (or titlecase) in the Help file anyway. The case of the parameter does not matter as AutoIt works case-insensitive Edited December 30, 2018 by water TheSaint 1 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...
TheSaint Posted December 30, 2018 Share Posted December 30, 2018 3 hours ago, water said: The case of the parameter does not matter as AutoIt works case-insensitive One of those things I keep forgetting. It always throws me when the Help file shows propercase instead of lowercase, which logically should be the default. Propercase or Uppercase should only be shown when they are actually required. A small failing of our wonderful Help file. Thanks for the reminder. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
water Posted December 30, 2018 Share Posted December 30, 2018 I have started a thread in the MVP forum to discuss this (and another) issue with the Excel (and maybe the Word) UDF. Thanks for the heads up 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...
LazyVasily Posted December 31, 2018 Author Share Posted December 31, 2018 TheSaint, Did everything you told me to do. #include <Excel.au3> #include <MsgBoxConstants.au3> Local $sWorkBook = "1.xls" Local $oExcel = _Excel_Open() If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error creating Excel object! @error = " & @error & ", @extended = " & @extended) Local $oWorkBook = _Excel_BookAttach($sWorkbook, "Title") If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error attaching to the workbook! @error = " & @error & ", @extended = " & @extended) $oWorkBook.ActiveSheet.Shapes.Range("Oval 1").Delete If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error deleting shape! @error = " & @error & ", @extended = " & @extended) This script does not work. Displays a window with the error: "Error attaching to the workbook! @error=1, extended = -2147352570" Link to comment Share on other sites More sharing options...
water Posted December 31, 2018 Share Posted December 31, 2018 When we try to attach to a workbook, it works. When you do, it doesn't. So we need more information: Which version of Excel do you run? Which version of AutoIt do you run? Can you post your workbook so we can try in our environment? 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...
LazyVasily Posted December 31, 2018 Author Share Posted December 31, 2018 water, 4 hours ago, water said: Which version of Excel do you run? Excel 2013x64 and Excel2007 Autoit 3.3.14.0 Again specify. File 1.xls-not started with a click. And at the time of running the script file 1.xls is ALREADY open. The script should find the window-not by the file path, but by the name "Title". 1.xls Link to comment Share on other sites More sharing options...
water Posted January 1, 2019 Share Posted January 1, 2019 To work with the x64 version of Excel your AutoIt script needs to be compiled for 64 bit as well. Could you please give this a try? 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...
LazyVasily Posted January 1, 2019 Author Share Posted January 1, 2019 water, Actually, I've always run scripts from the console. I just started compiling 64. Shows all the same error message. "Error attaching to the workbook! @error=1, extended = -2147352570" Link to comment Share on other sites More sharing options...
BrewManNH Posted January 1, 2019 Share Posted January 1, 2019 Your title text is wrong isn't it? Wouldn't it be "1.xls - Excel", or even "1.xls [Compatibility Mode] - Excel" if opened in a newer version of Excel? From what I can see the UDF doesn't do partial text matches, it's looking for the full actual title of the window. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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