PDA

View Full Version : Calling a previously running Word macro



Roderick
09-30-2017, 04:19 AM
It all starts with a dropdown list in the Ribbon Bar. There are four items in the list: Apples, bananas, oranges and pineapples.

On choosing one from the dropdown, it fires up a form through an OnAction callback which allows the user to say what they want to do with the bananas: fry, freeze, eat or store.

A user can now choose through a radio button their preferred choice and then it returns to the original calling macro, carries out a few procedures and then terminates. Job done! All works well.

However, on the user form there is a Cancel button which allows that person to say "On second thoughts, I don't want to do anything with bananas. I just want to cancel it all and return to modifying the document.

I've got an OnCancel_Click macro in the form which senses the user hitting the Cancel button. As it should, control now returns to the original macro that called the form and proceeds to do the remaining procedures.

What I want to achieve, is, that when the user hits the Cancel button, the form closes down (which already happens correctly) and then return to the original calling macro and halt it in its sequence, say with an Exit Sub command or a Go To instruction. The remaining commands will therefore not be processed.

However, if I had selected something to do with the bananas and then pressed OK on the user form then control returns to the calling macro and proceeds with further instructions. This is what is happening at the moment irrespective of whether I select OK or Cancel.

Everything seems to work OK in the sequence of going out but not on its return journey.

Could someone point me in the right direction, please?

gmaxey
09-30-2017, 06:40 AM
Use the form .tag property. Set it to one thing to execute and something else to cancel

e.g.,

In form:
Sub Cancel_Click
Tag = "Cancel"
Hide
End Sub

In calling macro:
With oFrm
.Show
If .Tag = "Cancel" Then
Exit Sub
Else
'Do normal processing.
End If

Roderick
09-30-2017, 01:53 PM
Thank you Greg for pointing me to the Tag property. Never knew about it.

At first it didn't work but then went over to your website where the Tag was explained in your article and all works OK now.

Thanks