levanduyet 0 Posted May 5, 2010 Dear All, How can I use AutoIt to Open one Excel File in Excel 2007 and Enable Macro also. Tks, LVD Share this post Link to post Share on other sites
exodius 1 Posted May 5, 2010 (edited) For opening Excel files, look at the Help File for functions that start with _Excel.As for enabling macros... Personally I'd try to rewrite the macro in AutoIt (for universality's sake) or try this post. Edited May 5, 2010 by exodius Share this post Link to post Share on other sites
levanduyet 0 Posted May 5, 2010 For opening Excel files, look at the Help File for functions that start with _Excel.As for enabling macros... Personally I'd try to rewrite the macro in AutoIt (for universality's sake) or try this post.Thank Exodius,Do you have another way?LVD Share this post Link to post Share on other sites
99ojo 0 Posted May 5, 2010 (edited) Hi, copied from a 'Juvigy' post, if you want to run the macro. For macro security settings the link from @exodius should help. Try: $oExcel = ObjCreate("Excel.Application") ;crete excel object $oExcel.WorkBooks.Open($FileName) ;open desired file containing the macro $oExcel.Run("Macro1") ;run the macro ;-)) Stefan Edited May 5, 2010 by 99ojo Share this post Link to post Share on other sites
laffo16 1 Posted May 6, 2010 (edited) hey guys im getting some strange things with excel, when i run _ExcelBookAttach from the latest offical build, i have an excel.exe process appear for a split second in my task manager, i think this causes the @error to return incorrectly. if i change bookattach method to FileName, it no longer causes the .exe to open. so i'm forced to use filename to have the error return correctly. i want to use the $oExcel.Run("") macro method mentioned above, but it only seems to work for me with the returned obj from _ExcelBookOpen, the returned obj from _ExcelBookAttach does not let me use .Run, any ideas? #include <Excel.au3> Global $filename = "test1.xls" Global $filepath = "C:\Documents and Settings\Administrator\Desktop\test1.xls" $oExcel = _ExcelBookAttach($filename, "FileName") If $oExcel = 0 Then $oExcel = _ExcelBookOpen($filepath, 1) EndIf _ExcelWriteCell($oExcel, "abc", 2, 2) $oExcel.Run("TestMacro") Edited May 6, 2010 by laffo16 Share this post Link to post Share on other sites
l3ill 70 Posted May 6, 2010 I didnt know about this command when I wrote my code for something similar so I just used the normal Excel Open Sheet commands and the a Send command to run the macro from inside excel, you have to assign the macro a shortcut first though ;-) ...in case you cant get it to work the other way. My Contributions...SnippetBrowserNewSciTEPathFinderText File ManipulationFTP Connection Tester / INI File - Read, Write, Save & Load Example Share this post Link to post Share on other sites
levanduyet 0 Posted May 7, 2010 hey guys im getting some strange things with excel, when i run _ExcelBookAttach from the latest offical build, i have an excel.exe process appear for a split second in my task manager, i think this causes the @error to return incorrectly. if i change bookattach method to FileName, it no longer causes the .exe to open. so i'm forced to use filename to have the error return correctly. i want to use the $oExcel.Run("") macro method mentioned above, but it only seems to work for me with the returned obj from _ExcelBookOpen, the returned obj from _ExcelBookAttach does not let me use .Run, any ideas? #include <Excel.au3> Global $filename = "test1.xls" Global $filepath = "C:\Documents and Settings\Administrator\Desktop\test1.xls" $oExcel = _ExcelBookAttach($filename, "FileName") If $oExcel = 0 Then $oExcel = _ExcelBookOpen($filepath, 1) EndIf _ExcelWriteCell($oExcel, "abc", 2, 2) $oExcel.Run("TestMacro") Yeah, It's a good question. Anybody know how to run the macro, enable the macro in the attached workbook. Tks, LVD Share this post Link to post Share on other sites
Juvigy 49 Posted May 7, 2010 Change $oExcel.Run("TestMacro") to $oExcel.Application.Run("TestMacro") Share this post Link to post Share on other sites