DawnRhoads
Mon Nov 21 16:00:03 CST 2005
Hi Greg -- thanks for the offer, but I feel like I've taken enough of your
time! It's easy enough for me to work around as is. If you're really
curious and want to take a look, I'm happy to send it to you, but only if you
are interested.
For the benefit of others, I discovered that it doesn't actually matter that
the drop down field appears before the checkboxes, what matters is that it is
in a table and that a hard return follows the drop down box somewhere in the
table cell. The table can be anywhere in the document. If I take the drop
down out of the table,viola, no error. If I remove any hard return AFTER the
drop down in the same table cell, again no error. Sure sounds like a bug in
Word to me.
If you want me to send the document, I'm not sure what your email is, let me
know where I can find it and I will send the document along.
Thanks again, appreciate your time and your help, what you came up with here
is *great*!
Dawn
"Greg Maxey" wrote:
> Dawn,
>
> Can't replicate that problem here. Send me the document. (Strip out your
> existing macros first) I will have a look if I get time.
>
>
> --
> Greg Maxey/Word MVP
> See:
>
http://gregmaxey.mvps.org/word_tips.htm
> For some helpful tips using Word.
>
> Dawn Rhoads wrote:
> > Hi Greg -- that does the trick, you rock! There is one very specific
> > set of circumstances that must be some kind of bug in Word that
> > causes an error, but I can work around it. But for some reason, if
> > there is a dropdown field, that is inside a table, that appears
> > before the first checkbox (yep, all three of those things must be
> > true to produce the error) for some reason I get a "the requested
> > member of the collection does not exist" error when it reaches this
> > line:
> >
> > If .FormFields(1).Type = wdFieldFormCheckBox Then 'If the first
> > formfield is a checkbox
> >
> > For the documents I'm working with I can just change around some
> > field type and still get this to work, which is a small price to pay
> > to be able to use such a cool macro! Of course, if you have any
> > thoughts on getting around that very werid problem, that would be
> > great -- but you've already worked a miracle as far as I'm concerned.
> >
> > Thanks so much for your help!
> >
> > ~Dawn Rhoads
> >
> >
> > "Greg Maxey" wrote:
> >
> >> Ok, try:
> >>
> >> Sub Test()
> >> Dim oPar As Paragraph
> >> ActiveWindow.View.ShowHiddenText = True
> >> On Error Resume Next
> >> ActiveDocument.Unprotect
> >> On Error GoTo 0
> >> For Each oPar In ActiveDocument.Paragraphs
> >> With oPar.Range
> >> If .FormFields.Count > 0 Then 'If there is a formfield
> >> If .FormFields(1).Type = wdFieldFormCheckBox Then 'If the first
> >> formfield is a checkbox
> >> If .FormFields(1).CheckBox.Value = False Then 'If its value
> >> is false
> >> oPar.Style = "Hidden"
> >> Else
> >> oPar.Style = "Normal"
> >> End If
> >> End If
> >> End If
> >> End With
> >> Next
> >> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
> >> ActiveWindow.View.ShowHiddenText = False
> >> End Sub
> >>
> >>
> >> --
> >> Greg Maxey/Word MVP
> >> See:
> >>
http://gregmaxey.mvps.org/word_tips.htm
> >> For some helpful tips using Word.
> >>
> >> Dawn Rhoads wrote:
> >>> Hi Greg -- Darn it, I came across a problem. This code works great
> >>> as long as the only type of field in the document is a checkbox.
> >>> However, I normally have several different kinds of fields in a
> >>> document. If there are other field types, I get a "bad parameter"
> >>> error. I found some code in another newsgroup posting talking about
> >>> this same issue, but I can't figure out how to incorporate it into
> >>> your code, I just keep creating a bunch of errors. Any ideas?
> >>> Thanks
> >>> in advance!
> >>>
> >>> If oField.Type = wdFieldFormCheckBox Then
> >>>
> >>> Also, for the benefit of anyone else reading this thread, one other
> >>> issue that I found is that it seems any hidden text must be visible
> >>> on screen when the macro runs in order for the code to work each
> >>> time (if it is run more than once on the same document). So, if I
> >>> unchecked a few boxes, ran the macro which hid some of the
> >>> paragraphs, and then went back and re-checked the boxes, and ran the
> >>> macro with hidden text not visible on the screen, the selected
> >>> paragraphs would not show up again. So I recorded a bit of code to
> >>> add to the beginning to show hidden text, and a bit at the end to
> >>> make it not visible again. I'm sure since I recorded that code, so
> >>> it's probably 5 times longer than it needs to be, but it seems to
> >>> work. :)
> >>>
> >>> With ActiveWindow
> >>> With .View
> >>> .ShowHiddenText = True
> >>> End With
> >>> End With
> >>>
> >>> Dim oPar As Paragraph
> >>> On Error Resume Next
> >>> On Error GoTo 0
> >>> For Each oPar In ActiveDocument.Paragraphs
> >>> If oPar.Range.FormFields.Count > 0 Then
> >>> If oPar.Range.FormFields(1).CheckBox.Value = False Then
> >>> oPar.Style = "Hidden"
> >>> Else
> >>> oPar.Style = "Normal"
> >>> End If
> >>> End If
> >>> Next
> >>> With ActiveWindow
> >>> With .View
> >>> .ShowHiddenText = False
> >>> End With
> >>> End With
> >>>
> >>>
> >>> "Greg" wrote:
> >>>
> >>>> No that was my goober. If there isn't a formfield in the para it
> >>>> will generate the error. Try:
> >>>>
> >>>> Sub Test()
> >>>> Dim oPar As Paragraph
> >>>> On Error Resume Next
> >>>> ActiveDocument.Unprotect
> >>>> On Error GoTo 0
> >>>> For Each oPar In ActiveDocument.Paragraphs
> >>>> If oPar.Range.FormFields.Count > 0 Then
> >>>> If oPar.Range.FormFields(1).CheckBox.Value = False Then
> >>>> oPar.Style = "Hidden"
> >>>> Else
> >>>> oPar.Style = "Normal"
> >>>> End If
> >>>> End If
> >>>> Next
> >>>> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
> >>>> End Sub
>
>
>