Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
tamilarasu
Champion
Champion

Macro to change certain input field values to uppercase

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

IP.png                                OP.png

Any help would be appreciated.

@ marcus_sommer Do you have any idea.?

1 Solution

Accepted Solutions
marcus_sommer

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

View solution in original post

8 Replies
ecolomer
Master II
Master II

Is this you need?

P_228301.png

marcus_sommer

Not very nice but it worked (you might need some adjustments to make it more stable, for example some error-routines).

- Marcus

tamilarasu
Champion
Champion
Author

Exactly. Could you please post the application or code here.? Thank you for you help.

tamilarasu
Champion
Champion
Author

Thank you for the prompt reply. I'll check the file by tommorow morning and let you know the status.

tamilarasu
Champion
Champion
Author

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.

marcus_sommer

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

tamilarasu
Champion
Champion
Author

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.

marcus_sommer

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