Vivi

Possible to automaticly add an macro to a doc/excel file ?

10 posts in this topic

hey guys,

is it possible to add automaticly a macro to a word file ?

i already saw the word udf (word.au3 standard include) but it didnt had any functions for it.

do you guys know a way ?

 

Best Regards,

 

Vivi

Share this post


Link to post
Share on other sites



For Excel it works this way:

$oExcel.Application.VBE.ActiveVBProject.VBComponents.Import("C:\temp\Modul1.bas")

so I think for Word it should be similar:

$oWord.Application.VBE.ActiveVBProject.VBComponents.Import("C:\temp\Modul1.bas")

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
1 hour ago, water said:

For Excel it works this way:

$oExcel.Application.VBE.ActiveVBProject.VBComponents.Import("C:\temp\Modul1.bas")

so I think for Word it should be similar:

$oWord.Application.VBE.ActiveVBProject.VBComponents.Import("C:\temp\Modul1.bas")

 

hugh vouch !

worked.

now i just need to make it silent :P

 

my code :

 

$word = ObjCreate("Word.Application")
$word.visible = False
$word.Documents.open(@ScriptDir & "/doc.doc")
$word.Application.VBE.ActiveVBProject.VBComponents.Import(@ScriptDir  & "/macro.txt")
$word.Application.Quit

 

 

NY6w2wR.png

Share this post


Link to post
Share on other sites

Use the Word UDF that comes with AutoIt:

#include <Word.au3>

Global $oWord = _Word_Create()
Global $oDoc = _Word_DocOpen($oWord, @ScriptDir & "/doc.doc")
$oWord.Application.VBE.ActiveVBProject.VBComponents.Import(@ScriptDir  & "/macro.txt")
_Word_DocSave($oDoc)
_Word_DocClose($oDoc)
_Word_Quit($oWord)

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

NB: Add some error checking after each call to a _Word* function. Examples can be found in the example scripts provided in the help file for each function.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

hey man,

i just realized that the macro gets added, but not in the file itself.

GVC2QSL.png

 

 

9i4Mf5n.png

 

Share this post


Link to post
Share on other sites

Should then be:

$oDoc.VBProject.VBComponents.Import("C:\temp\Modul1.bas")
1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

works great.

 

thanks

Edited by Vivi

Share this post


Link to post
Share on other sites

:)

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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