Hello,MS Access have useful command DoCmd.RunMacro I try to add reference to Access VBA library in Corel, but can not run any macros in CorelPlease give me advice how to run macro in Corel using macroname as variable or text stringDoCmd.RunMacro "MacroName"Ormymn="MacroName
DoCmd.RunMacro mymn
Greetings!
community.coreldraw.com/.../gmsmanager.runmacro
Thank YouA little more explanation, pleaseGMSManager.RunMacro is prefect to run macro from command moduleMy situation is a little differentAssume we have userform with name ufMyFormufMyForm has 2 commandbuttons" with names cbTest1 and cbTest2
Sub cbTest1_Click()MsgBox "cbTest1 Clicked"End Sub
Sub cbTest2_Click()cbTest1_Click 'This work wellEnd SubBut I need this method schematic
Sub cbTest2_Click()myMacro = "cbTest1_Click"WhatToRunCommand? myMacroEnd SubI tryGMSManager.RunMacro "GlobalMacros", "Tests.Test1" 'work! I Have Macro module Tests and Sub Test1 in it
I try GMSManager.RunMacro "GlobalMacros", "ufMoveControl.CommandButton11_Click" 'not work
ufMoveControl is my userform
How to work around and to make to work?Call "CommandButton11_Click" 'This not workCall CommandButton11_Click 'This work
Is a method to make identifier from variable?A little more explanation
Why I need thisWhen I create my code projects i separate them to Stage1, Stage2, Stage3 etc.Code Stage1 is bound to CommandButton1_ClickCode Stage2 is bound to CommandButton2_ClickCode Stage3 is bound to CommandButton3_Click
When I test my code first click CommandButton1, then CommandButton2, then CommandButton3I have on my Userform Frame1In VBE I drag/drop CommandButton1 and CommandButton2 in Frame1Then I wont Sub Frame1_Click()CommandButton1_ClickCommandButton2_ClickEnd Sub
The names of command buttons in Frame1:Dim MYARRAY(5000, 3) As Variant'MYARRAY = Array(Frame1.Controls.Count)
'MsgBox Frame1.Controls.Count 'work'Frame1.ZOrder 1'MsgBox Frame1.ActiveControl.Name 'workFor Each MYCTRL In Frame1.ControlsMYARRAY(MYCTRL.Left, 1) = MYCTRL.LeftMYARRAY(MYCTRL.Left, 2) = MYCTRL.NameMYARRAY(MYCTRL.Left, 3) = MYCTRL.Caption
'MsgBox MYCTRL.Name 'WORK'MsgBox MYCTRL.Left 'WORK'READ CONTROLS in Frame1 LEFT TO RIGHTNext
For X = 1 To 5000If MYARRAY(X, 1) > 0 Then'MsgBox MYARRAY(X, 1) & Chr(13) & MYARRAY(X, 2) & Chr(13) & MYARRAY(X, 3)'MsgBox MYARRAY(X, 2)'Run (MYARRAY(X, 2) & "_click") 'not workMsgBox MYARRAY(X, 2) & "_Click"'CommandButton11_Click 'work
'AAA = "ufMoveControl" & "." & MYARRAY(X, 2) & "_Click"AAA = MYARRAY(X, 2) & "_Click"
MsgBox "AAA = " & AAA'Call AAA 'not work'Call CommandButton11_Click 'work'Call "CommandButton11_Click" 'NOT WORK
'ufMoveControl.CommandButton11_Click
End If'sort array ascending, from left to rightNext
End Sub
Казано накратко, искам при кликване върху Frame1 да се изпълнят всички Click процедури на командните бутони, разположени върху Frame1. Изпълнението да става от ляво надясно - първо се изпълнява Click кодът на най-ляво разположения бутон, после на този до него, след това на третия от ляво надясно и т.н.
In short, I want clicking on Frame1 to execute all the Click procedures on the command buttons located on Frame1. The execution should take place from left to right - first the Click code is executed on the leftmost button, then on the one next to it, then on the third one from left to right, etc.Any idea will be accepted gratefully
You do not use a string to call a function, only in a reflection scenario that strings will be used. If you use the reserved word "Call" you will need to use parentheses. But you have a designer problem in your code, if you need to use an algorithm in more than one part of your code you must create a function to encapsulate this code, as in some cases the event handler functions require some parametersCall statement (VBA) | Microsoft Learn
Thank You very much for this answer!
I keep looking for a working answer that will work for me.
As I told you previously, you cannot call a function by its name with a string, this is a language specification, you were able to do this in languages that support reflection, but VBA does not have this support. Generally reflection is used to modify and access at runtime.
And as I said previously, you can encapsulate your codes in public functions that become "Macros", as a macro is merely a name for a function and use GMSManager.RunMacro to call them, but this is quite clumsy.
Here I am using Reflection with C#, with reflection you were able to list the functions of a class (methods) and execute them by name
Maybe there is some solution for VBA. Good luck!
Task has several solutions. From a simple "condition tree" to CallByName calls.You can also organize a For-Each loop of controls inside the Frame and call its method for each, for example, Change.
I said the wrong things, CallbyName is very similar to reflection, so it should work for it, I have to stop giving my opinion about VBA and just stick to C#