levanduyet Posted May 5, 2010 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
exodius Posted May 5, 2010 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
levanduyet Posted May 5, 2010 Author 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
99ojo Posted May 5, 2010 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
laffo16 Posted May 6, 2010 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
l3ill Posted May 6, 2010 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... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
levanduyet Posted May 7, 2010 Author 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
Juvigy Posted May 7, 2010 Posted May 7, 2010 Change $oExcel.Run("TestMacro") to $oExcel.Application.Run("TestMacro")
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