huskies Posted March 18, 2009 Posted March 18, 2009 How Do I embed an Excel Macro into a new excel workbook if I already have the macro saved in a txt file? Right now what I do is I open the txt file and copy the macro I've written go to excel, send key presses to record macro, then go to edit, then I paste my macro in and then I run it. It is kind of long and tedious and takes a lot of time for autoit to run it, is there a simpler way? expandcollapse popupWinActivate("[TITLE:Microsoft Excel]", "") WinWaitActive("[TITLE:Microsoft Excel]") $ScriptHome = @ScriptDir & "\" & "macro.txt" send("{ALT}") sleep(300) send("t") sleep(300) send("m") sleep(300) send("r") sleep(300) send("macro") sleep(300) send("{ENTER}") sleep(300) send("{ALT}") sleep(300) send("t") sleep(300) send("m") sleep(300) send("r") sleep(300) send("{ALT}") sleep(300) send("t") sleep(300) send("m") sleep(300) send("m") sleep(300) send("!e ") sleep(300) WinWaitActive("Microsoft Visual Basic - ") sleep(300) send("{CTRLDOWN}a{CTRLUP}") sleep(300) send("{DEL}") sleep(300) ShellExecute("macro.txt", "", @ScriptDir, "edit") WinWaitActive("macro") sleep(400) send("{CTRLDOWN}a{CTRLUP}") sleep(300) send("{CTRLDOWN}c{CTRLUP}") sleep(300) WinClose("macro") WinWaitClose("macro") WinActivate("Microsoft Visual Basic - ") WinWaitActive("Microsoft Visual Basic - ") sleep(300) send("{CTRLDOWN}v{CTRLUP}") sleep(300) send("{ALT}") sleep(300) send("f") sleep(300) send("c") sleep(300) send("{ALT}") sleep(300) send("t") sleep(300) send("m") sleep(300) send("m") sleep(300) send("!r") sleep(5000) _ExcelBookSaveAs($oExcel, $Address & "\" & @mon & "." & @mday & " Result.xls", "xls", 0, 1) <It Shall Be Done>
ResNullius Posted March 20, 2009 Posted March 20, 2009 This post shows how to use the Excel COM object to import a .BAS file:http://www.autoitscript.com/forum/index.ph...st&p=562189
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