Sign in to follow this  
Followers 0
huskies

Autoit to Embed(Add) Macro to Excel?

2 posts in this topic

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>

Share this post


Link to post
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
Sign in to follow this  
Followers 0