Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello All,
I have one input field in my application. User can be allowed to enter some defined names in the field. I need to use a macro to change certain lower case entries to uppercase. I have tried a macro to loop through cells but it's not working properly. I want result like below.
Current Table Expected Reult
Any help would be appreciated.
@ marcus_sommer Do you have any idea.?
Well, you are right - it didn't work if there are duplicates within the values because fieldindex() couldn't handle it and returned FALSE for these values - therefore a workaround with the concat-function (the needed RecNo is created within the script):
sub x
set vFld=ActiveDocument.GetField("Type")
vValueIndex = ActiveDocument.Evaluate("Concat(RecNo, ',', RecNo)")
vValue = ActiveDocument.Evaluate("Concat(Type, ',', RecNo)")
vValueIndex = split(vValueIndex, ",")
vValue = split(vValue, ",")
for i = 0 to ubound(vValueIndex)
vFld.SetInputFieldValue vValueIndex(i) - 1, ucase(vValue(i))
next
end sub
- Marcus
Is this you need?
Not very nice but it worked (you might need some adjustments to make it more stable, for example some error-routines).
- Marcus
Exactly. Could you please post the application or code here.? Thank you for you help.
Thank you for the prompt reply. I'll check the file by tommorow morning and let you know the status.
I have tried your code (already tried somewhat similar) and it's working. If I filter some rows in the table and run the macro, it's replacing the not selected rows. Please have a look at the attachment.
It's now adjusted and takes only the possible values from the selections. The challange was (only) to synchronize the possible values and their count with the real field-positions:
sub x
set vInput = ActiveDocument.Fields("Type").GetPossibleValues
set vFld=ActiveDocument.GetField("Type")
for i = 0 to vInput.Count -1
vValueIndex = ActiveDocument.Evaluate("Fieldindex('Type', '" & vInput.Item(i).Text & "')")
vValue = ucase(vInput.Item(i).Text)
'msgbox vValueIndex & " = " & vValue
vFld.SetInputFieldValue vValueIndex - 1, vValue
next
end sub
- Marcus
Markus,
If the field "Type" has unique values, the solution works fine. It shows macro window in the below attached example for repeated values. When I checked the vValueIndex value it shows as "0".
vFld.SetInputFieldValue vValueIndex - 1, vValue => vFld.SetInputFieldValue 0 -1, A
Thanks for your help.
Well, you are right - it didn't work if there are duplicates within the values because fieldindex() couldn't handle it and returned FALSE for these values - therefore a workaround with the concat-function (the needed RecNo is created within the script):
sub x
set vFld=ActiveDocument.GetField("Type")
vValueIndex = ActiveDocument.Evaluate("Concat(RecNo, ',', RecNo)")
vValue = ActiveDocument.Evaluate("Concat(Type, ',', RecNo)")
vValueIndex = split(vValueIndex, ",")
vValue = split(vValue, ",")
for i = 0 to ubound(vValueIndex)
vFld.SetInputFieldValue vValueIndex(i) - 1, ucase(vValue(i))
next
end sub
- Marcus