Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How do I save field selections in a macro variable and then pass them back?

I have a sheet that I do not want date selections applied to so I want to run a macro when the sheet opens to save the values in a variable and then clear the field selections.  On exiting the sheet I want to take the values stored in the variables and update the field values again.  I have the following for storing the values.

Sub SiteCompareNoDate

  'Set variables to store the date selections.

  set DtSelStart = ActiveDocument.Fields("Start Date").GetSelectedValues

  set DtSelComp = ActiveDocument.Fields("Completed Date").GetSelectedValues

  'Clear the date field selections.

  ActiveDocument.Fields("Start Date").Clear

  ActiveDocument.Fields("Completed Date").Clear

End Sub

Now I would like to create another macro that will reapply the values once I leave the sheet.  How would I accomplish this?

Jake Kibler

4 Replies
marcus_sommer

I suggest to use actions which set a variable-value per getfieldselections() or concat() instead of use of macros. Here you will get some ideas: Tracking the historical selections.

- Marcus

Not applicable
Author

Originally I was.  I had sheet On Open triggers that were setting the variables (1 variable per field) then clearing the field selections.  Then actions sheet on leave that would take the values in each of the variables and set the field value back.

It worked great when I was working on it locally, but when we deployed to our server which uses AJAX the sheet on open and on leave triggers do not work.

MarcoWedel

Hi,

maybe using an Alternate State could be an alternative here.

hope this helps

regards

Marco

marcus_sommer

In this case macros won't help (rather the opposite especially within AJAX) because the issue is the trigger regardless if an action or a macro is behind them. But it's new for me that an ActivateSheet don't work (OnOpen is often difficult) maybe there is a conflict with multiple actions or with the QV release - which one is in use?

If this don't help you will need another kind of usability - maybe with alternate states like suggested from Marco or the disabling from the native sheet-navigation and replacing them with buttons/textboxes.

- Marcus