Apply VBA Word Macro - From Another Document To Active Document - Com Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sarah

Apply VBA Word Macro - From Another Document To Active Document - Com

25 Mar 2017, 21:18

Hi Autohotkey experts,


I am looking for some help, I am a newbie as of yesterday.

I am trying to apply a vba word macro that is stored in a different file.

Example

C:\Users\Home\Desktop\Highlightmacros.docm

has a macro named "yellowparagraphs" stored in it.

How can I access and apply this macro to my current active document?

I know the obvious solution is to copy it to my normal.dotm but that is not what I am looking for.
I just want to apply the macro stored in that file to my active document when i am editing.

I referenced this below and read all the com tutorials found here but I don't know how to do this and the below gives me an error

Directory = L:\Today
Filename := " " Directory "\Test.rtf" ;Path of File
MacroName = PrtAF10851 ; name of the existing MSWord Macro
COM_Init()
Word := COM_CreateObject("Word.Application")

COM_Invoke(Word,"Visible=",False)
Docs :=
COM_Invoke(Word,"Documents")
COM_Invoke(Docs,"Open",Filename)

COM_Invoke(Word, "Run", "!"MacroName)
COM_Release("!"MacroName)

COM_Release(Docs)
COM_Release(Word)
COM_Term()
Sleep 2000

From <https://autohotkey.com/board/topic/4637 ... ro-by-ahk/>


please can an expert help me thank you very much

sarah
User avatar
Jovannb
Posts: 268
Joined: 17 Jun 2014, 02:44
Location: Austria

Re: Apply VBA Word Macro - From Another Document To Active Document - Com

26 Mar 2017, 05:17

Hi,

I costs me hours to learn how to access VBA-Macro structure of Excel by AHK, it is porobably the same for Word

Have a look at part of my code at https://autohotkey.com/boards/viewtopic.php?f=5&t=28963

J.B.
AHK: 1.1.37.01 Ansi, 32-Bit; Win10 22H2 64 bit, german
sarah

Re: Apply VBA Word Macro - From Another Document To Active Document - Com  Topic is solved

26 Mar 2017, 09:53

Hello JB,

thank you for your reply, let me study it and i will be back

I am a newbie so its a lot to understand quickly but i am trying and i like autohotkey as i had some hotkeys that showed me you can use it easily

thank you

:)
sarah

Re: Apply VBA Word Macro - From Another Document To Active Document - Com

26 Mar 2017, 12:21

Hi,

i have been testing the code below and I cant seem to get it to work. Same as Idea as what i explained earlier.

The macro Name BlueZoe >> is stored in Macros.xlsm

This Macro I would like to apply to my open workbook

Code: Select all

;------------------------------------

oExcel := ComObjCreate("Excel.Application")                                ; Create a handle to a new excel application
oExcel.Visible := false                                                              ; By default excel sheets are invisible
xlspath = C:\Users\Home\Desktop\Macros.xlsm
SplitPath, xlspath, xlsFile
oExcel.Workbooks.Open(xlspath)                                             ; open an existing file
;oExcel.Run(xlsfile "!BlueZoe")                                                ; Run the Macro in that File

;--------------------------------

;APPLY TO CURRENT OPEN WORK BOOK ACTIVE SHEET

XL := ComObjActive("Excel.Application")                 ;creates a handle to your Application object

;xlsfile := xl.ActiveWorkbook.name		;retrieves the name of the active workbook


xl.Run(xlsfile "!BlueZoe")			;run excel macro
xl.ActiveWorksheet.Activate


I am not sure if the syntax is right?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Albireo and 140 guests