L
L
loljeene2014-12-01 06:01:36
Macros
loljeene, 2014-12-01 06:01:36

How to programmatically insert a macro into XLS?

There is an automation object - XLS file. Automation is most easily done through a VBA macro due to the complex formatting of the document.
The macro is written, but there is a problem - each time the system issues a new XLS file.
How can I programmatically embed a macro into an existing XLS file.
Solution language - any, up to autoit, if he can

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
loljeene, 2014-12-01
@loljeene

I will answer myself:

#include <excel.au3>
Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
Local Const $sMessage = "Выберите файл."
Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "XLS (*.xls)", 1)
local $sFilePath1 = ($sFileOpenDialog)
Local $oExcel = _ExcelBookOpen($sFilePath1)
$oExcel.VBE.ActiveVBProject.VBComponents.Import(@ScriptDir & "\\macro.bas")
$oExcel.Run("test")
Exit
; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite("err.number is: " & tab & $oError.number & @CRLF & _
            "err.windescription:" & tab & $oError.windescription & @CRLF & _
            "err.description is: " & tab & $oError.description & @CRLF & _
            "err.source is: " & tab & $oError.source & @CRLF & _
            "err.helpfile is: " & tab & $oError.helpfile & @CRLF & _
            "err.helpcontext is: " & tab & $oError.helpcontext & @CRLF & _
            "err.lastdllerror is: " & tab & $oError.lastdllerror & @CRLF & _
            "err.scriptline is: " & tab & $oError.scriptline & @CRLF & _
            "err.retcode is: " & tab & $oError.retcode & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question