Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
shumailh
Creator III
Creator III

Simple Macro Code

Can anyone please help on the below function, I am trying to select the value U and V on the sheet activation but it's not working with the below code... [:s]

sub MakeSelection()
ActiveDocument.Fields("BLOCKCODE1").Select 'U','V'
ActiveDocument.Fields("BLOCKCODE2").Select 'U','V'
ActiveDocument.Fields("BLOCKCODE3").Select 'U','V'
end sub

Regards,
Shumail Hussain

1 Solution

Accepted Solutions
sparur
Specialist II
Specialist II

Hi,

try that example:

sub MakeSelection()

set curentField = ActiveDocument.Fields("BLOCKCODE1")

'Initialize array of values for selection

set arrayOfValues = curentField.GetNoValues

'Add New Element in array
arrayOfValues.add

'Fill this element
arrayOfValues(0).Text = "U"
arrayOfValues(0).IsNumeric = false


'Add New Element in array
arrayOfValues.add

'Fill this element
arrayOfValues(1).Text = "V"
arrayOfValues(1).IsNumeric = false

curentField.SelectValues arrayOfValues

end sub

for more details see in attachment and APIguide.qvw.
best regards, Anatoly.



View solution in original post

5 Replies
sparur
Specialist II
Specialist II

Hi,

try that example:

sub MakeSelection()

set curentField = ActiveDocument.Fields("BLOCKCODE1")

'Initialize array of values for selection

set arrayOfValues = curentField.GetNoValues

'Add New Element in array
arrayOfValues.add

'Fill this element
arrayOfValues(0).Text = "U"
arrayOfValues(0).IsNumeric = false


'Add New Element in array
arrayOfValues.add

'Fill this element
arrayOfValues(1).Text = "V"
arrayOfValues(1).IsNumeric = false

curentField.SelectValues arrayOfValues

end sub

for more details see in attachment and APIguide.qvw.
best regards, Anatoly.



Anonymous
Not applicable

Hi Shumail,

Here's an example for selecting U and V in a field called F1:

sub Sel()
ActiveDocument.Fields("F1").Select "U"
ActiveDocument.Fields("F1").ToggleSelect "V"
end sub

This can be created using actions instead of running it as a macro although it shouldn't really make any difference.

shumailh
Creator III
Creator III
Author

your code is working perfectly... Smile

Thanks Johannes!

Regards,
Shumail Hussain

shumailh
Creator III
Creator III
Author

Thanks Anatoly, your code is also working.

Regards,
Shumail Hussain

Not applicable

Thanks for sharing .. worked wonders