Vivi Posted February 20, 2016 Share Posted February 20, 2016 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 Link to comment Share on other sites More sharing options...
water Posted February 20, 2016 Share Posted February 20, 2016 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") Vivi 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Vivi Posted February 20, 2016 Author Share Posted February 20, 2016 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 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 Link to comment Share on other sites More sharing options...
water Posted February 20, 2016 Share Posted February 20, 2016 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) Vivi 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Vivi Posted February 20, 2016 Author Share Posted February 20, 2016 Just now, water said: 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) thanks man. works perfectly Link to comment Share on other sites More sharing options...
water Posted February 20, 2016 Share Posted February 20, 2016 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Vivi Posted February 20, 2016 Author Share Posted February 20, 2016 hey man, i just realized that the macro gets added, but not in the file itself. Link to comment Share on other sites More sharing options...
water Posted February 20, 2016 Share Posted February 20, 2016 Should then be: $oDoc.VBProject.VBComponents.Import("C:\temp\Modul1.bas") Vivi 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Vivi Posted February 20, 2016 Author Share Posted February 20, 2016 (edited) works great. thanks Edited February 20, 2016 by Vivi Link to comment Share on other sites More sharing options...
water Posted February 20, 2016 Share Posted February 20, 2016 Vivi 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
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