I'm searching for a way to call a VBA macro from another document.When I'm running e.g.: Application.GMSManager.RunMacro "GlobalMacros", "Test.ZMenExec", pIdthis works, but If I replace 'GlobalMacros' with the name of my module, it does not work anymore
Maybe you didn't wont to say what you did...
'GlobalMaros' is not a module, of course and that 'my module' where it is located? In a GMS file or in a document module?
Most likely I do not (yet) understand the macro management at Corel, I'm working mainly with Office tools, in that world macros and command bars are handled quite different.Since the GMS is the only thing I saw until now where I can take a macro from to give a menu bar an action I want to use those macros to start a subroutine within one of my documents.So my menu bar shall contain 3 or 4 buttons, when clicking one of it a macro under GMS shall check, which document is open and then start a macro inside the document. Means: Depending on the open document(s) a click on the same menu button will cause a different action.This simply shall help me to develop my tools with having the possibility to start one macro in test also from the Corel environment and not only from the VBA-Editor.
Do you work in what version of Corel?
2017
I'm afraid you cannot...
I know only two methods of calling a procedure but both of them from another GMS, not document module...
GMSManager.Projects("GlobalMacros").Macros("Teste.testMsgBox").Run GMSManager.RunMacro "GlobalMacros", "Teste.testMsgbox"
Procedures from document modules cannot be called using those ways...
Thanks for your answer, FaneDuru,it confirms what I always feared, that this is not possible. but I thought maybe somebody knows a backdoor.I remember under X6 I was able to do something like this, but sometimes the progress of the software is not always a progress in usability
Instead of trying to call code in the document why don't you set a Property in the document. Then read the Property to decide which code path you want to run. So for example you could set your property like this:
ActiveDocument.Properties("MyMacroName", 1) = "Blue"
Then you might have a Subroutine like this:
Sub ChangeOnOpenDoc() Dim s As Shape Set s = ActiveLayer.CreateRectangle(0, 0, 1, 1) If ActiveDocument.Properties("MyMacroName", 1) = "Red" Then s.Fill.ApplyUniformFill CreateRGBColor(255, 0, 0) ElseIf ActiveDocument.Properties("MyMacroName", 1) = "Blue" Then s.Fill.ApplyUniformFill CreateRGBColor(0, 0, 255) Else s.Fill.ApplyUniformFill CreateRGBColor(0, 255, 0) End If End Sub
Hope that helps,
-Shelby