Jump to content

Autoit to Embed(Add) Macro to Excel?


Recommended Posts

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?

WinActivate("[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>
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...