Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I have a field with a single value. I am trying to write a small macro to check and see if the value in that field is selected.
If the value is selected then I don't want anything to happen. If the value is not selected, then I have another macro (which already works) that I want to run.
Can anyone help?
Thanks,
Scott
Scott,
This will work:
sub MacroName
set f=ActiveDocument.Fields("FieldName")
set s=f.GetSelectedValues
if s.count = 1
' do nothing
else
AnotherMacroName
end if
end sub
Hi Michael,
I inserted the script and added the field name and macro names. I got a message, "Macro Parse Failed. Functionality was Lost."
Suggestions?
Thanks,
Scott
Scott,
The code is just missing the "then"
if s.count = 1 then
If you use the Check button on the macro editor it will point out the line in error instad of the generic "Macro Parse Failed..." message.
Here's another suggestion for testing the field, which I think is slightly simpler.
sub MacroName2
if ActiveDocument.Evaluate("GetSelectedCount(FieldName)") = 1 then
msgbox "is Selected"
else
msgbox "not Selected"
end if
end sub
See if I misspelled anything. The macro is rather simple, should work.
Sure, I missed "then" - thanks Rob