LazyVasily Posted December 24, 2018 Share Posted December 24, 2018 Hello. Who knows - as a script to remove the figure "Oval 1" from the open workbook of Excel 1.xls ? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted December 25, 2018 Moderators Share Posted December 25, 2018 @LazyVasily you are simply going to have to provide more information if you want help, our crystal ball is in the shop. How about a screenshot of the figure you are trying to remove, or better yet, an example of the spreadsheet itself. Xandy 1 "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...
JoHanatCent Posted December 25, 2018 Share Posted December 25, 2018 Try $oExcel = _Excel_Open() $o_Excel = _Excel_BookOpen($oExcel, @DesktopDir & "\Book 1.xls") $o_Excel.ActiveSheet.Shapes.Range(("Oval 1")).Delete _Excel_BookClose($o_Excel) Link to comment Share on other sites More sharing options...
LazyVasily Posted December 25, 2018 Author Share Posted December 25, 2018 JoHanatCent, This script constantly reopens the xls file. I already have an xls file open-no need to open it again. Because part of the contents of the Excel-disappears if the file is not saved. How to remove the shape "Oval 1" in an already open Excel file, without reopening ? Link to comment Share on other sites More sharing options...
AutoBert Posted December 25, 2018 Share Posted December 25, 2018 Use https://www.autoitscript.com/autoit3/docs/libfunctions/_Excel_BookAttach.htm Link to comment Share on other sites More sharing options...
LazyVasily Posted December 25, 2018 Author Share Posted December 25, 2018 AutoBert, This code doesn't work. #include <Excel.au3> $oWorkBook = _Excel_BookAttach(@ScriptDir & "\1.xls") $oExcel = _Excel_Open() $oWorkBook.ActiveSheet.Shapes.Range(("Oval 1")).Delete It works only in rare exceptions - if you close all Excel files and run the desired file 1.xls by clicking on it. In other cases, this code does not work. Gives an error "Variable must be of type Object". How to delete the shape "Oval 1"regardless of how the file 1.xls was open-click or through the Excel program ? Link to comment Share on other sites More sharing options...
water Posted December 25, 2018 Share Posted December 25, 2018 #include <Excel.au3> #include <MsgBoxConstants.au3> $oExcel = _Excel_Open() If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error creating Excel object! @error = " & @error & ", @extended = " & @extended) $oWorkBook = _Excel_BookAttach(@ScriptDir & "\1.xls") 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) You first have to call _Excel_Open to create the Excel object! I have added error checking so you know what went wrong. 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 25, 2018 Author Share Posted December 25, 2018 water, File 1.xls is open at the time of running your script. An error window appears : Link to comment Share on other sites More sharing options...
water Posted December 25, 2018 Share Posted December 25, 2018 Did you have a look at th help file? The error code is explained as: Workbook not found. Does the Excel file exist in the script directrory? Is the name correct? is the extension correct? 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 25, 2018 Author Share Posted December 25, 2018 water, You don't quite understand what I'm asking. Your script works. But it works only in one case. It only works if the file " 1.xls" - will be opened by clicking on the file. If you open the file 1.xls in another way, the script does not work. After all, the file can be opened by hyperlink or simply through the Excel menu. The file thus opened is " 1.xls " - the script does not recognize and displays an error window. I asked - how to remove the shape "Oval 1" if the file 1.xls was opened not by clicking on this file, but in another way ? The file can be opened via the Excel menu (and now AutoIt-script does not see it). Link to comment Share on other sites More sharing options...
Nine Posted December 25, 2018 Share Posted December 25, 2018 1 hour ago, LazyVasily said: You don't quite understand what I'm asking. I don't think asking (looks like more of an order to me) for us to give you the solution all chewed up will service you. So try a few things, bring back the different codes you have tested. “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...
water Posted December 25, 2018 Share Posted December 25, 2018 As long as the workbook 1.xls is opened from @ScriptDir and is open when the AutoIt script is started it doesn't matter how you open it. _Excel_BookAttach compares the specified filepath which should match in this cases. If it still doesn't work, try other $sMode options. 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 25, 2018 Author Share Posted December 25, 2018 (edited) water, Advise - as replace "$Mode FileName" on "$sMode Title" in your script (Title of the Excel window) ? In Help no found example for "$sMode Title" (https://www.autoitscript.com/autoit3/docs/libfunctions/_Excel_BookAttach.htm) Edited December 25, 2018 by LazyVasily Link to comment Share on other sites More sharing options...
water Posted December 25, 2018 Share Posted December 25, 2018 My advice is: Read the help file That's what it is made for BTW: Not for every possible value of a parameter you'll find an example in the help file. But the examples give you an idea how it works. 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 25, 2018 Author Share Posted December 25, 2018 water, But the help is missing an example for "$sMode Title" : https://www.autoitscript.com/autoit3/docs/libfunctions/_Excel_BookAttach.htm Link to comment Share on other sites More sharing options...
water Posted December 25, 2018 Share Posted December 25, 2018 That's exactly what I told you in my last post. Seems you need to show some effort yourself 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 25, 2018 Share Posted December 25, 2018 @LazyVasily You do really want to respect your nick ? “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...
LazyVasily Posted December 26, 2018 Author Share Posted December 26, 2018 (edited) water, Independently created a script similar to the example in the Help. The script does not work. Shows the error "Error attaching to the workbook". #include <Excel.au3> #include <MsgBoxConstants.au3> Opt('WinTitleMatchMode', -2) $oExcel = _Excel_Open() $sTitle = "1.xls" If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error creating Excel object! @error = " & @error & ", @extended = " & @extended) $oWorkBook = _Excel_BookAttach($sTitle) 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) #include <Excel.au3> #include <MsgBoxConstants.au3> ;Opt('WinTitleMatchMode', -2) Local $oWorkBook = "1.xls" $oExcel = _Excel_Open() If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error creating Excel object! @error = " & @error & ", @extended = " & @extended) $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) What have I done wrong ? How to change this script so that it finds the right window 1.xls by Title ? Edited December 26, 2018 by LazyVasily Link to comment Share on other sites More sharing options...
water Posted December 26, 2018 Share Posted December 26, 2018 In the second script you use $sWorkbook in _Excel_BookAttach but you use variable $oWorkbook to assign the title of the workbook ("1.xls") 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 understand. I made changes. The script still can't find the window "1.xls". #include <Excel.au3> #include <MsgBoxConstants.au3> ;Opt('WinTitleMatchMode', -2) Local $sWorkBook = "1.xls" $sExcel = _Excel_Open() If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error creating Excel object! @error = " & @error & ", @extended = " & @extended) $sWorkBook = _Excel_BookAttach($sWorkbook, "title") If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error attaching to the workbook! @error = " & @error & ", @extended = " & @extended) $sWorkBook.ActiveSheet.Shapes.Range("Oval 1").Delete If @error Then Exit Msgbox($MB_ICONERROR, "Error", "Error deleting shape! @error = " & @error & ", @extended = " & @extended) Shows the error "Error attaching to the workbook". 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