using Command Manager in VBA

using Command Manager in VBA

3DAli
Collaborator Collaborator
802 Views
1 Reply
Message 1 of 2

using Command Manager in VBA

3DAli
Collaborator
Collaborator

Hi There, 

 

I came across this situation and it has puzzled me, if you can share your thoughts and experience, would be greatly appreciated

 

when I use command manager like below (it could be any command, this is an example)

ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")

 

if its sitting in a module in VBA and you run it as macro, it works fine without any issue, however , if you insert a userform and place the code in a command button on the form, it wont work, and it wont give you any warning or error as if it's run properly but it does not in fact fire up the command. see below

 

Private Sub CommandButton1_Click()
Dim pd As PartDocument
Set pd = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
Set oDef = pd.ComponentDefinition

pd.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"

Dim F As Face
Set F = pd.ComponentDefinition.SurfaceBodies(1).Faces(2)

Call pd.SelectSet.Select(F)

Dim cd As ButtonDefinition
Set cd = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")

' To void user interaction
'Call ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, "C:\DXF\Test.dxf")

Call cd.Execute

End Sub

 

same code works perfectly fine when its place in a module (see below)

 

3DAli_0-1639770810733.png

 

 

any idea as to whether or not this is a normal behavior or if there is any missing steps. 

 

Regards

Ali

0 Likes
Accepted solutions (1)
803 Views
1 Reply
Reply (1)
Message 2 of 2

3DAli
Collaborator
Collaborator
Accepted solution

Thanks to @adam.nagy , the user form must be modeless and that solves the issue.

0 Likes