How do I choose the Start of a Selection?

C

coginthemachine

I am trying to cut certain sections of text based on their Checkbox value (if
Chekcbox.Value=False, delete the section up to the next CheckBox). The code
(graciously donated by Dian Chapman) works great and steps through each
Checkbox as expected. However, each time I use a Selection command (either
MoveStart or MoveEnd) it always starts wherever the cursor was when I ran the
macro. I need to set the Selection Start at each Checkbox in the For Loop as
it processes.

Here is the code I am working on:

Dim fld as FormField
For each fld in ActiveDocument.FormFields
If fld.CheckBox.Value = false then
?? Start selection at current Checkbox
?? moveselection end to next checkbox
delete section

Else
; Do nothing, checkbox checked (true) means keep the section
End if
Next fld
Can anyone give me some direction on how to do this? I appreciate it.
 
D

Doug Robbins

Try the following:

Dim fld As FormField, myrange As Range, Flag As Boolean
Flag = False
For Each fld In ActiveDocument.FormFields
If fld.CheckBox.Value = False Then
If Flag = False Then
Set myrange = fld.Range
Flag = True
Else
myrange.End = fld.Range.Start - 1
myrange.Delete
Flag = False
End If
End If
Next fld


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top