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
I think it should work according to his need description...
Even if this should be considered off-topic can you imagine/suggest a workaround for bypassing of a document Page event? Or a way to Enable document events in X8? Do you know/imagine which should be the reason of this behavior in X8? Is it a bug or only my installation has a problem (64bit) even if I uninstalled and reinstalled it several times?
Do Document Events work in 2017?
Thanks in advance!
P.S. How could you post such a nice formatted code since the HTML option is not present in the new editor? Did you use Tools -> Source Code (after hilite processing)?
Hi Shelby,thanks for this idea, but it does not solve my problem: What I want to do is something while my document is open and not only while I'm opening it.To be more concrete: I want to be able to start quickly different sub routines, e.g. to click on one icon to see, if the modification on a shape works like expected, but for the case that it destroyed my test environment, I click on a different icon which starts first the (time consuming) part to recreate the shape(s).Actually I have in my modules a sub routine starting with aaa which contains only the call of the module I'm working on. So: If the procedure my cursor is actually in can not be started with F5, I get a list of possible macros. And then the needed is always on top. But in some cases you need different macros to test, so this method has it disadvantages.
I would still appreciate that Shelby suggestion works well for all your (enumerated) cases...
It does not work only on document opening!
It works whenever you press that button and check which is "MyMacroName" property in the active document, acting accordingly...You can test the macro on the document level (using in code all the time 'activeDocument') and pass the final necessary procedure at a GMS level linked to the specific Document property (like parameter, maybe)...
Of course, it is not exactly what you did before and according to the number of involved documents and procedures it may require some work, but it is a nice workaround, a think...