jc0r Posted November 7, 2012 Posted November 7, 2012 Hi all What i am trying to do i believe is relatively simple. I have an Excel workbook open call test.xls and i would like to get AutoIt to execute one of the macros stored wiithin the workbook. The macro is called "just1" I created the following code: $oExcel.run("just1") but get the following error: >"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\jc0r\Desktop\test.au3" C:\Users\jc0r\Desktop\test.au3 (1) : ==> Expected a "=" operator in assignment statement.: $oExcel.run("just1") $oExcel^ ERROR >Exit code: 1 Time: 0.238 Any ideas please? Many thanks jc0r
jc0r Posted November 7, 2012 Author Posted November 7, 2012 Nope sorry same error: >"C:Program FilesAutoIt3SciTE..autoit3.exe" /ErrorStdOut "C:Usersjc0rDesktoptest.au3" C:Usersjc0rDesktoptest.au3 (1) : ==> Expected a "=" operator in assignment statement.: $oExcel.run = "just1" $oExcel^ ERROR >Exit code: 1 Time: 0.225 I dont know if it matters but i am using Excel 2003 and i do not have anything else in my script other than that one line. I am not sure if i need to reference to the workbook or not?
Andreik Posted November 7, 2012 Posted November 7, 2012 In this case the error is clear, you don't have an excel object. Use Excel UDF to open your document and then run the macro.
jc0r Posted November 7, 2012 Author Posted November 7, 2012 This is not possible, i need to Excel document to already be open and i use AutoIt to call macros from within the workbook. Do you know if this is possible please?
Andreik Posted November 7, 2012 Posted November 7, 2012 Look in help file at _ExcelBookOpen() function. This function will return you an object that allow run method to run your macro.
water Posted November 7, 2012 Posted November 7, 2012 Use function _ExcelBookAttach of the Excel UDF to attach to an already open workbook. Then you can run the macro. 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
jc0r Posted November 7, 2012 Author Posted November 7, 2012 Many thanks for you help so far. I only have 2 posts left for today as i am a new member but i am struggling with what you've provided so far. This is my current script however it just seems to open another copy of the workbook and not do anything #include <Excel.au3> #include <File.au3> Local $sFilePath = "c:test.xls" _ExcelBookOpen($sFilePath) Local $oExcel = _ExcelBookAttach($sFilePath) $oExcel.run("just1") I do not want it to open another workbook, as you stated, i want it to attach to the existing one but when i remove the line: _ExcelBookOpen($sFilePath) The whole thing breaks down. This seems tricky when all i want to do is execute a macro in Excel? Thanks
water Posted November 7, 2012 Posted November 7, 2012 I would use: #include <Excel.au3> Global $sFilePath = "c:test.xls" Global $oExcel = _ExcelBookAttach($sFilePath) ; Returns the workbook object $oExcel.parent.run("just1") ; Run method needs the application object 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
jc0r Posted November 7, 2012 Author Posted November 7, 2012 I cannot thank you enough, this worked just as i desired. I am not allowed to post anymore today as i am new so thanks for taking the time with my problem. Regards
water Posted November 7, 2012 Posted November 7, 2012 Glad to be of service 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
envirowiz Posted September 26, 2013 Posted September 26, 2013 Hello, I am not able to DL the Beta 2 Excel Rewrite zip file: Is there another link?
water Posted September 26, 2013 Posted September 26, 2013 Thre have been 40 downloads. And so far I haven't heard of a problem. Do you get an error message or is the download incomplete? 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
envirowiz Posted October 15, 2013 Posted October 15, 2013 I found the problem - corporate firewall. Thanks.
water Posted October 15, 2013 Posted October 15, 2013 Glad the problem could be solved 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
envirowiz Posted November 20, 2013 Posted November 20, 2013 Water, I am using the $oExcel.parent.Run("MacroName") as you stated, but get this error message: ==> The requested action with this object has failed.: $oExcel.parent.Run("ADRReport") $oExcel.parent.Run("ADRReport")^ ERROR Is something else needed at the end of the script line?
water Posted November 20, 2013 Posted November 20, 2013 Can you add a COM error handler so we get more detailed error information? The help file for ObjEvent shows what you need to do. 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
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